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 DataGrid 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.