Hi Pritesh, the solution to your problem is by using PropertyChangedCallback and attach an EventHandler to it.
Here is how I did:
public partial class Window1 : Window
{
public static DependencyProperty CountProperty;
public static DependencyProperty DependOneProperty;
public static DependencyProperty DependTwoProperty;
static Window1()
{
CountProperty = DependencyProperty.Register("Count",
typeof(int),
typeof(Window1),
new UIPropertyMetadata(0));
DependOneProperty = DependencyProperty.Register("DependOne",
typeof(int),
typeof(Window1),
new UIPropertyMetadata(0,
new PropertyChangedCallback(OnDependChange)));
DependTwoProperty = DependencyProperty.Register("DependTwo",
typeof(int),
typeof(Window1),
new UIPropertyMetadata(0,
new PropertyChangedCallback(OnDependChange)));
}
public int Count
{
get { return (int)GetValue(CountProperty); }
set { SetValue(CountProperty, value); }
}
public int DependOne
{
get { return (int)GetValue(DependOneProperty); }
set { SetValue(DependOneProperty, value); }
}
public int DependTwo
{
get { return (int)GetValue(DependTwoProperty); }
set { SetValue(DependTwoProperty, value); }
}
private static void OnDependChange(DependencyObject sender,
DependencyPropertyChangedEventArgs e)
{
Window1 window = (Window1)sender;
if (e.Property == DependOneProperty)
{
window.DependOne = (int)e.NewValue;
}
else
{
window.DependTwo = (int)e.NewValue;
}
window.Count = window.DependOne + window.DependTwo;
}
public Window1()
{
InitializeComponent();
this.DataContext = this;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
DependOne = DependOne + 1;
DependTwo = DependTwo + 1;
}
}
Hope this helps. :)
Do let me know if you have any doubts.