Hello,
Welcome to our Microsoft Q&A platform!
You want to dynamically change the value of DiscountedPrice
when the Price
changes. This is possible.
You can register a callback method for value changes when creating a DependencyProperty
, specifically created as follows:
public static readonly DependencyProperty PriceProperty =
DependencyProperty.Register(nameof(Price), typeof(string), typeof(Product), new PropertyMetadata("0.00",new PropertyChangedCallback(Price_Changed)));
private static void Price_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if(e.NewValue!=null && !e.NewValue.Equals(e.OldValue))
{
double price = Convert.ToDouble(e.NewValue);
double discountedPrice = price * 0.8;
//Assign values to TextBlock or perform other operations
}
}
Thanks.