例如,我有: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