如何使用MVVM在combobox中设置默认文本

我使用MVVM模式绑定WPF中的combobox。 我能够使用combobox绑定字符串列表,但我不知道如何在combobox中设置默认值。 好吧,我有一个名字列表,其中包含“A”,“B”,“C”和“D”。 现在我希望默认情况下“A”应该作为默认值。

谢谢

       

 public class NameViewModel { private IList _nameList = new List(); public IList Names { get; set; } public NameViewModel() { Names = GetAllNames(); } private IList GetAllNames() { IList names = new List(); names.Add("A"); names.Add("B"); names.Add("C"); names.Add("D"); return names; } } 

我认为你应该尝试使用ListItem。 ListItem具有Selected属性

我想说实现这个的最简单方法是绑定所选项目……

         

 public class NameViewModel { private IList _nameList = new List(); public IList Names { get; set; } public string SelectedName { get; set; } public NameViewModel() { Names = GetAllNames(); SelectedName = "A"; } private IList GetAllNames() { IList names = new List(); names.Add("A"); names.Add("B"); names.Add("C"); names.Add("D"); return names; } }