Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change binding value, not binding itself

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.

like image 479
Sam Avatar asked May 27 '10 14:05

Sam


People also ask

How do I change the value of bindings?

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.

How does binding work in C#?

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.

What is binding path in WPF?

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#.


1 Answers

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.

like image 58
Kris Avatar answered Oct 09 '22 12:10

Kris