For example, I have:
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"/>
How I can (need to) set List as a DataContext from the XAML? (and delete "comboBox1.DataContext = List" from the code-behind)