I have two textboxes and if I change the value in one of them, the value in the other textbox should be calculated. This need to work in both directions.
In my ViewModel I have a property/object called NewProductCount
private ProductCount newProductCount;
public ProductCount NewProductCount
{
get
{
return newProductCount;
}
set
{
newProductCount = value;
if (newProductCount.PackingUnits != 0 || newProductCount.SellingUnits != 0)
{
newProductCount.SellingUnits = (int)newProductCount.PackingUnits * SelectedProduct.PurchasePackaging.UnitsPerPackage;
newProductCount.PackingUnits = newProductCount.SellingUnits / SelectedProduct.PurchasePackaging.UnitsPerPackage;
}
NotifyPropertyChanged();
}
}
In my View(xaml) I have a stackpanel with two textboxes. The datacontext of the stackpanel has a binding to the NewProductCount property in my ViewModel. Inside this stackpanel I have two textboxes. The first one has a binding to PackingUnits property of the NewProductCount object and the second one has a binding to the SellingUnits property of the NewProductCount object. Now the problem is when I change something in one of the textboxes I want to go to the setter of NewProductCount property in my ViewModel.
This is what my View looks like:
<StackPanel DataContext="{Binding NewProductCount}" >
<Label Content="Number of selling units:"/>
<TextBox Text="{Binding SellingUnits}"/>
<Label Content="Number of packing units"/>
<TextBox Text="{Binding PackingUnits}"/>
</StackPanel>
I have also tried updatesourcetrigger (propertychanged) on the two textboxes but that did not fire the setter of the NewProductCount property in my ViewModel.
Thanks in advance,
Arne