4

カスタム クラス MyPerson があります。すべての (関連する) プロパティは、INotifyPropertyChanged を実装します。それを表示する UserControl を作成しましたが、すべて正常に動作しました。MyPerson.FirstName (文字列) などのプロパティへのバインディングはすべて機能します。期待どおりに表示および更新 (双方向バインディング) されます。

コード ビハインドでもっと複雑なことをしたいので、PropertyType が MyPerson の DependencyProperty を作成したかったのですが、DependencyProperty、特に PropertyChangedCallback 部分を構築する方法がわかりません。

これはできますか?どうして?

4

1 に答える 1

1

この記事を読む -カスタム依存関係プロパティ

何かのようなもの -

public static readonly DependencyProperty MyPersonValueProperty = 
      DependencyProperty.Register( "MyPersonValue", typeof(MyPerson), 
         typeof(MyPersonControl), new FrameworkPropertyMetadata(null, 
             FrameworkPropertyMetadataOptions.AffectsRender,
               new PropertyChangedCallback(OnPersonChanged) ) ); 

public MyPerson ThePerson
{ 
    get { return (MyPerson)GetValue(MyPersonValueProperty); }
    set { SetValue(MyPersonValueProperty, value); }
}

private static void OnPersonChanged(DependencyObject d, 
                                 DependencyPropertyChangedEventArgs e)
{
    // Property change code here
}
于 2013-03-17T09:07:43.720 に答える