例如,我有:WPF结合问题
MainWindows.cs
public partial class MainWindow : Window
{
public List<Player> List;
public MainWindow()
{
InitializeComponent();
List = new List<Player>()
{
new Player() {Id = 1, Name = "Tom"},
new Player() {Id = 2, Name = "Bob"},
new Player() {Id = 3, Name = "Any"},
};
comboBox1.DataContext = List;
}
public class Player
{
public string Name { get; set; }
public int Id { get; set; }
}
}
XAML:<ComboBox ItemsSource="{Binding}" DisplayMemberPath="Name"/>
我怎样才能(需要)设置列表从XAML一个DataContext? (并从代码隐藏中删除“comboBox1.DataContext = List”)
我学习MVVM现在,感谢意见@dain – johnny 2011-03-31 17:10:51