Having this structure and a combobox:
public abstract class A: UserControl
{
public string MachineName { get; protected set; }
...
}
public partial class MainWindow : Window
{
private List<A> m_listA = new List<A>();
public MainPanel()
{
InitializeComponent();
DataContext = this;
cbMachines.ItemsSource = m_listA;
cbMachines.SelectedIndex = 0;
cbMachines.DisplayMemberPath = "MachineName";
}
}
If I execute it I have the list of elements of the combobox perfectly filled but the selected one is empty and throws a binding error:
System.Windows.Data Error: 40 : BindingExpression path error: 'Name' property not found on 'object'
''Grid' (Name='')'. BindingExpression:Path=Name; DataItem='Grid' (Name=''); target element is
'TextBlock' (Name=''); target property is 'Text' (type 'String')
It seems that, it takes the grid of "A" main control as datacontext it seems that, it takes the main control as data context, but i need the usercontrol as datacontext.
How can i do this?