which event fires when a listbox finished databinding? - silverlight

The ASP.NET GridView (and other controls) has the very handy DataBound event, which fires after the GridView finishes databinding. Is there an equivalent event for the Silverlight ListBox (WP7.1)?
My ListBox changes constantly based on user input and I would like to scroll the listbox to a certain item.

As far as I know there is no such event.
But you could use a more generic change listener like ItemsChanged:
listBox1.ItemContainerGenerator.ItemsChanged += new ItemsChangedEventHandler(ItemContainerGenerator_ItemsChanged);
This will also react on normal list changes but you can easily filter these.

The ListBox has a SelectedItem property. Just set it to one of the items, or set the SelectedValue and that will automatically scroll it to make visible.
Here is the MSDN reference of that property: http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selecteditem.aspx

Related

Should a ViewModel control focus in the View

I have an ItemsControl binding to a collection in the ViewModel. As a result of user input, a new item gets added to the collection and this gets displayed on the View.
The item is also a View-ViewModel pair, the View contains a TextBox that I would like to receive focus immediately after being added to the collection.
How do I set the focus to a TextBox without referencing the View from within the ViewModel? Are attached properties the way to go here?
well you can do this by creating a behaviour..
have a look here to get an idea of behaviours controlling focus

Setting Focus to a Control after the Loading of the DataGrid

I have a UserControl in WPF and it contains a variety of controls in it... The most important being the DataGrid Control. The DataGrid control is bound to an Observable Collection list. This list filled with different items based on couple of filters selected by the user. Now, once the DataGrid displays all the data. I want to set the Focus on the first (Filters) combobox on my usercontrol. Is there any way to know when the DataGrid has completely loaded??? Is there any DataTrigger I could set that i could trigger to inform me that Grid was refreshed with new list and I can set the ComboBox to focus. Basically i'm not able to set the focus to the first control on my UserControl when the data in the DataGrid has been repopulated... Please let me know if anyone knows how to resolve this issue!!
Thanks in advance.
I hate to work in code behind but sometimes that is only way. This can be done in two ways according to me:
Use EventAggregator to raise the event from your ViewModel once you are done with your filtering logic in it. Listen to this event in view code behind and in the handler do firstCombo.Focus()
Second is bit dirty, So there must be the button or the last control after which you apply filter on your listview. In the buttonClickHandler/or any event of the last control (like selectionchange) directly do firstCombo.Focus(). In this case the moment you will press your button focus will move to combo.
Thanks

How to listen changes in Observable collection in WPF?

I have user control in which I have placed a Listview and Richtext box control.
ListView is binded to my custom collection.
Below the listview I placed a richtext box in which I want to display my custom text. The custom text is created from the custom collection.
I want to recreate the custom text whenever any thing change in my custom collection.
How can I acheive this. I have implemented INotifyProperty changed event in my Viewmodel.
In the viewmodel, my custom collection resides.
Use the CollectionChanged property from ObservableCollection.

Silverlight ListBox OnMouseOver event

I have a ListBox that is being bound to data from a WCF service. When the user hovers over one of the ListBoxItems, I want to display related text in a separate region. Each of the items in the data collection to which the list is being bound has a Description property.
How can I wire up to the mouseover event for a particular ListBoxItem?
Have a look at this thread, I think you might find your answer:
WPF Listbox Show Button in ItemTemplate on MouseOver

WPF listview databinding - How do I force update to underlying object without tabbing out?

I have a WPF ListView that is bound to a BindingList<T>. The binding works like a charm, but I have to tab out of the cell to get the bound property to update....this is an issue because most users don't tab out of the last column before clicking the save button.
How do I force the list view to "persist" the changes to the bound DataContext without doing something hackish.
Bindings in WPF have a property called "UpdateSourceTrigger" which tells the Binding when to update the thing the UI is bound to. By default, it's set to "LostFocus" for the Text property which is what you're most likely using.
Change the trigger to "PropertyChanged" in your binding like this:
Text="{Binding Foo,UpdateSourceTrigger=PropertyChanged}"
... and now the source "Foo" property will be updated as the Text changes in the UI.
There's also an "Explicit" setting for UpdateSourceTrigger which is handy if you need to hold off writing any changes to the source until, say, the user clicks the OK button.

Resources