DependencyPropertiesについて不思議に思っていただけです。DependencyProperty PropertyChangedCallbackとコードを直接セッターに配置する
通常、DependencyPropertyが変更された後にコードを実行するときに、この種のコーディング標準が表示されます。
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));
が、これは悪い習慣を考えられている -
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
}
しかし、私は、実装のこの種を見たことがないとは思いませんか?
ありがとうございます!
プロパティをバインドすると、それは 'SetBinding'です... –