I've got a WPF UserControl containing a DependencyProperty (MyProperty).
The DependencyProperty is bound to a Property in the DataContext.
Now in the UserControl I want to change the value of the bound property. But if I assign MyProperty = NewValue
the Binding is lost and replaced by NewValue.
What I want to achieve is change the DataContext-property the DependencyProperty is bound to.
How do I achieve this instead of changing the binding?
To clarify: using something like MyTextBox.Text = "0";
I'll release the binding. How would I set Text, leave the binding intact so the property Text is bound to will change, too.
You can use SetCurrentValue. The SetCurrentValue method changes the effective value of the property, but existing triggers, data bindings, and styles will continue to work. This did the same as direct assignment to the Property: On OneWay-binding it dropped the binding, on TwoWay-binding it changed the bound property.
C# interfaces - Blazor, API, UWP, WPF, Office Data binding allows the flow of data between UI elements and data object on user interface. When a binding is established and the data or your business model changes, then it reflects the updates automatically to the UI elements and vice versa.
Binding path syntax. Use the Path property to specify the source value you want to bind to: In the simplest case, the Path property value is the name of the property of the source object to use for the binding, such as Path=PropertyName . Subproperties of a property can be specified by a similar syntax as in C#.
You can use SetCurrentValue.
The SetCurrentValue method changes the effective value of the property, but existing triggers, data bindings, and styles will continue to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With