So I am trying to programmatically create Two-Way bindings for dynamically generated tabs, and the Path requirement is giving me trouble.
edit When I do not use two-way binding and remove the path/source/mode/trigger it works correctly
Here is the binding I am using:
Binding schedBind = new Binding();
schedData = Converter.GetTemplate(false);
schedGrid.DataContext = schedData;
schedBind.Path = new PropertyPath(DataGrid.DataContextProperty);
schedBind.RelativeSource = new RelativeSource(RelativeSourceMode.Self);
schedBind.Mode = BindingMode.TwoWay;
schedBind.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;
schedGrid.SetBinding(DataGrid.ItemsSourceProperty, schedBind);
However when I create an instance of the tab that uses the D开发者_如何转开发ataGrid schedGrid
it shows up blank. The DataTable schedData
does have information in it, so why isn't the binding filling the DataGrid
?
Help?
I fixed it by adding a class DataHolder
which had a SchedData
property. I then set the instance of the DataHolder
to the DataContext
and set the Path=SchedData
.
Not exactly what I had hoped for but it works.
精彩评论