我是新與WPF和依賴屬性和我的問題可能是完全新手...依賴項屬性默認值
我有以下依賴屬性:
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;
}
的問題是,我想OnIsEditablePropertyChanged
中的代碼也會被執行,以用於我的屬性的默認值,這不會發生。
我在做什麼錯,或者我應該怎麼做你的意見?
預先感謝您。
你在哪裏設置默認值? – 2011-04-20 08:55:06
在創建屬性時:新的FrameworkPropertyMetadata(false ..這是不夠的嗎? – Dummy01 2011-04-20 08:57:11