I am afraid that you cannot set the readonly static field again unless you do this with the βnewβ one.
You might be able to catch a DataContext modified by binding data to a DataContext dependency dependency. for example Register a new dp named "MyDataContext" and create a binding.
The DataContext is the binding source, and MyDataContext is the target binding, i.e. DataContext ---> MyDataContext. So every time you get a DataContext MyDataContext dp, change the callback. I think this will work, but not tested.
The code is as follows:
// dp declaration.. public static readonly DependencyProperty MyDataContextProperty = DependencyProperty.Register(null, "MyDataContext", typeof(object), typeof(MyControl), new PropertyMetadata(MyDataContextChangedCallback)); // create binding in constructor or initialization. Binding binding = new Binding("DataContext"); BindingOperations.SetBinding(this, MyDataContextProperty, binding);
thanks
source share