I am new to WPF and dependency properties, and my question might be a complete newbie ...
I have the following dependency property:
public static readonly DependencyProperty IsEditableProperty = DependencyProperty.Register("IsEditable", typeof(bool), typeof(EditContactUserControl), new FrameworkPropertyMetadata(false, OnIsEditablePropertyChanged)); public bool IsEditable { get { return (bool)GetValue(IsEditableProperty); } set { SetValue(IsEditableProperty, value); } } private static void OnIsEditablePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { EditContactUserControl control = source as EditContactUserControl; bool isEditable = (bool)e.NewValue; if (isEditable) control.stackPanelButtons.Visibility = Visibility.Visible; else control.stackPanelButtons.Visibility = Visibility.Collapsed; }
The problem is that I want the code in OnIsEditablePropertyChanged executed also for the default value for my property, which is not happening.
What am I doing wrong, or how should I do it in my opinion?
Thanks in advance.
source share