記事

依存プロパティは他の入力の値に基づいてプロパティの値を計算する方法を提供する為の既存のプロパティの拡張です。

WPFで使うほとんどのプロパティは依存プロパティ です。

<RadioButton Margin="36,95,122,0" Name="radioButton1" VerticalAlignment="Top">RadioButton</RadioButton>
<Button Height="23" HorizontalAlignment="Left" Margin="52,40,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click">Button1</Button>

他の入力の値って何? 
テーマ 
ユーザー設定 
データ バインディング
アニメーション/ストーリーボード 
リソースやスタイルなどの多目的のテンプレート 
要素ツリー内の他の要素との親子のリレーションシップから判断される値

なにができるの? 
自己完結型の検証 
既定値 
他のプロパティに対する変更を監視するコールバック
プロパティ値を強制するシステム 

public static readonly DependencyProperty CurrentProperty = DependencyProperty.Register(
  "Current", typeof(int), typeof(UserControl1));
Currentプロパティ 
Int 型 
UserControl1というクラスのプロパティ

public static readonly DependencyProperty CurrentProperty = DependencyProperty.Register("Current", typeof(int), typeof(UserControl1),
    new PropertyMetadata(0,
    new PropertyChangedCallback(OnCurrentChanged),
    new CoerceValueCallback(Current_coercevalue)),
    new ValidateValueCallback(Current_validatevalue));
初期値 0 
OnCurrentChanged 変更監視 
CoerceValue 強制 
ValidateValue 検証

 

ダウンロード
 TitleOwnerCategoryModified DateSize (Kb)