I already spent hours on this, and similar topics did not help. :(
I've got an object of type "Chart" which contains a List "LineItems". I want to bind LineItems programmatically to a DataGrid in an UserControl.
Usercontrol XAML:
<DataGrid Name="myData" AutoGenerateColumns="True">
Usercontrol Code behind:
public void SetItemSource(ChartingBase.Chart chart)
{
//DataGrid.ItemsSource = chart.LineItems; // working!
// this is not working:
this.DataContext = chart;
Binding b = new Binding( "LineItems" );
b.Mode = BindingMode.TwoWay;
b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
myData.SetBinding( DataGrid.ItemsSourceProperty, b );
}
Setting just the ItemsSource works. Creating the binding manually does not work and I have no clue what else I could try. Thanks!