只是想知道DependencyProperties。DependencyProperty PropertyChangedCallback vs將代碼直接放置到setter中
通常我在DependencyProperty更改後執行某些代碼時看到了這種編碼標準。
public int SomeProperty
{
get { return (int)GetValue(SomePropertyProperty); }
set { SetValue(SomePropertyProperty, value); }
}
public static readonly DependencyProperty SomePropertyProperty =
DependencyProperty.Register("SomeProperty", typeof(int), typeof(MainWindow), new UIPropertyMetadata(new DependencyPropertyChangedEventHandler(OnSomePropertyChanged)));
private static void OnSomePropertyChanged(object obj, DependencyPropertyChangedEventArgs e)
{
//Some logic in here
}
但我不認爲我從來沒有見過這樣的實施 -
public int SomeProperty
{
get { return (int)GetValue(SomePropertyProperty); }
set
{
SetValue(SomePropertyProperty, value);
//Execute code in here
}
}
public static readonly DependencyProperty SomePropertyProperty =
DependencyProperty.Register("SomeProperty", typeof(int), typeof(MainWindow), new UIPropertyMetadata(0));
這被認爲是一種不好的做法?
謝謝!
如果你綁定一個屬性它是'SetBinding' ... – 2012-02-28 01:18:05