开发者

MVVM Question about default values in combo boxes

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 the MoveCurrentTo method (don't forget to set IsSynchronizedWithCurrentItem to true on the ComboBox)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜