I have a combo box on a view that will have a default of "Active" when the form is loaded. Whose job is it to set the combobox to开发者_JAVA百科 "Active", the code behind in the loaded method or the View Model?
Bill
I'd say it's the ViewModel's job. There are at least 2 approaches to do it:
- bind the
SelectedItem
of the combo to a property of the ViewModel, and set this property to the value you want - obtain the default view for the collection (
CollectionViewSource.GetDefaultView
) and set the current item with theMoveCurrentTo
method (don't forget to setIsSynchronizedWithCurrentItem
to true on theComboBox
)
精彩评论