innovasoft
asked on
Autoscroll a ListBox with databinding
Hello everybody
I got a ListBox with a databinding and I would like that to automaticly scroll to the bottom when a new item is added.
I know that I can use the ScrollIntoView() method to scroll the ListBox. But I can't use this, because the ListBox gets its items by a databinding.
Does anyone know a solution to my problem?
Thank you for your help!
Urs
I got a ListBox with a databinding and I would like that to automaticly scroll to the bottom when a new item is added.
I know that I can use the ScrollIntoView() method to scroll the ListBox. But I can't use this, because the ListBox gets its items by a databinding.
Does anyone know a solution to my problem?
Thank you for your help!
Urs
ASKER
oh, I forgot to tell: it's Silverlight
yes, I know that it works with ScrollIntoView. But the problem is, that I have the ListBox in the view bound to a property in the model. I did this, that I don't have to refresh the listbox manually. But now, the view doesn't really have an event when the listbox is updated with a new item. So there is no moment when I can use this ScrollIntoView.
Or is there something like an event "ItemsUpdated"?
yes, I know that it works with ScrollIntoView. But the problem is, that I have the ListBox in the view bound to a property in the model. I did this, that I don't have to refresh the listbox manually. But now, the view doesn't really have an event when the listbox is updated with a new item. So there is no moment when I can use this ScrollIntoView.
Or is there something like an event "ItemsUpdated"?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes, I think there is a difference. I have separated the model and the view. So the employeeList would be in the model while the ListBox is in the view. Since the model doesn't know the view, it can't do the lstEmployees.ScrollIntoVie w method.
But as I'm writing this, I think I could fire a custom event such as newItemAdded. The view should listen to that so I could put this code in the view anyway :)
Thank you for your help!
But as I'm writing this, I think I could fire a custom event such as newItemAdded. The view should listen to that so I could put this code in the view anyway :)
Thank you for your help!
YourListBox.ScrollIntoView
YourListBox.SelectedIndex = YourListBox.Items.Count - 1;