I have a class with 3 dependent properties A, B, C. The values ββof these properties are set by the constructor, and each time one of the properties A, B or C changes, the recalculate () method is called. Now, at the runtime of the constructor, this method is called 3 times, because the 3 properties A, B, C are changed. However, this is not necessary, since the recalculation method () cannot do anything really useful without all three of the given properties. So what is the best way to notify you of a property change, but bypassing this change notification in the constructor? I was thinking of adding a property change to the constructor, but then every object of the DPChangeSample class will always add more and more notification of changes. Thanks for any hint!
class DPChangeSample : DependencyObject
{
public static DependencyProperty AProperty = DependencyProperty.Register("A", typeof(int), typeof(DPChangeSample), new PropertyMetadata(propertyChanged));
public static DependencyProperty BProperty = DependencyProperty.Register("B", typeof(int), typeof(DPChangeSample), new PropertyMetadata(propertyChanged));
public static DependencyProperty CProperty = DependencyProperty.Register("C", typeof(int), typeof(DPChangeSample), new PropertyMetadata(propertyChanged));
private static void propertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((DPChangeSample)d).recalculate();
}
private void recalculate()
{
}
public DPChangeSample(int a, int b, int c)
{
SetValue(AProperty, a);
SetValue(BProperty, b);
SetValue(CProperty, c);
}
}