Reputation: 403
I have a custom control in which I created a custom DependencyProperty
called TheObject
that can contain a generic object.
<comp:MyControl TheObject="{Binding Country}" />
Sometimes, I need to set the TheObject
internally (by code, internally to the control).
I did something like this:
this.TheObject = new Country();
But I realized that it is causing the loss of the DataBinding
and the control becomes not responding to data changes.
What I really want is that this new object remains attached to the existing DataBinding
of the property.
Upvotes: 2
Views: 667
Reputation: 184506
Use SetCurrentValue
:
This method is used by a component that programmatically sets the value of one of its own properties without disabling an application's declared use of the property. The SetCurrentValue method changes the effective value of the property, but existing triggers, data bindings, and styles will continue to work.
this.SetCurrentValue(TheObjectProperty, new Country());
Upvotes: 3