2013年4月12日金曜日

依存関係プロパティの簡単な記述法

依存関係プロパティをいちいち記述するのは面倒なものです
簡単な書き方として、以下の操作があるようです

1. VisualStudio上でctrl - k - x を同時押し
2. コードスニペットの挿入からNetFX30を選択
3. "依存関係プロパティの挿入"を選択
        public int MyProperty
        {
            get { return (int)GetValue(MyPropertyProperty); }
            set { SetValue(MyPropertyProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));

4. パラメータの異なる部分を直す
    public int <<< こことか < ここはICommandにする
    MyPropertyProperty < お好みで... PlotExchangeCommand とか
    を直すと、"DependencyProperty.Registerの部分も修正してくれる

0 件のコメント:

コメントを投稿