i'm looking for a possibility to Update a TextBox TextProperty while typing in an other Textbox. I got a Couple of Double Properties, all entered via Textboxes and i got 1 ReadOnly Property using the Double Properties for doing some Math and returning the result. I want that result to be displayed in a ReadOnly TextBox (WPF) and it should update automatically when typing/changing an Input Parameter TextBox.
As i worked with JavaFX the last years i could use a deepbinding to do that:
DoubleBinding calcBind = new DoubleBinding(){
{
super.bind(PropA, PropB, PropC);
}
@Override
protected double computeValue(){
return (PropA * PropB / PropC)
}
};
The Dependencies statet with super.bind(...) are automatically checked if they changed and the result is automatically updated.
Now i'm just lookin for a possibility to realize that in C#
As said i am using a couple of properties. Also INotifyPropertyChanged is implemented. So PropA, B and C stating OnPropertyChanged("PropA") when set. The Calculation is done in a Readonly Property like
public Double MathProp
{
get
{
return PropA*PropB/PropC;
}
}
I am Binding it via Code to a TextBox TextProperty.
Binding mathBinding = new Binding
{
Source = ObjectHolding.MathProp,
Path = new PropertyPath("MathProp"),
UpdateSourceTrigger = UpdateSourceTrigger.Explicit,
Mode = BindingMode.OnyWay
};
TextBox txtMathBox = new TextBox();
txtMathBox.SetBinding(TextBox.TextProperty, mathBinding);
I used the Explicit Trigger to do it the "BruteForce"-Way and updating it manually when a KeyEvent occurs. But its just not working very well and i dont like that way of resolving the problmen. There has to be a more elegant way. I hope u could point me in the right direction. I thought about using a converter instead of a ReadOnly Property to do the calculations. But i am not converting i am just doing some math and not changing the types.
Would be glad if u got some hints for me.
Thanks