I have a control with two properties. One is a DependencyProperty
, the other is an \"alias\" to the first one. How do I raise the PropertyChanged
Implement INotifyPropertyChanged
in your class.
Specify a callback in the property metadata when you register the dependency property.
In the callback, raise the PropertyChanged
event.
Adding the callback:
public static DependencyProperty FirstProperty = DependencyProperty.Register(
"First",
typeof(string),
typeof(MyType),
new FrameworkPropertyMetadata(
false,
new PropertyChangedCallback(OnFirstPropertyChanged)));
Raising PropertyChanged
in the callback:
private static void OnFirstPropertyChanged(
DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
PropertyChangedEventHandler h = PropertyChanged;
if (h != null)
{
h(sender, new PropertyChangedEventArgs("Second"));
}
}