1 / 15

WPF 依存プロパティは すばらしい?

WPF 依存プロパティは すばらしい?. えムナウ(児玉宏之) Microsoft MVP for Visual-Developer C# 2005/01-2008/12. アジェンダ. はじめに 依存プロパティの概要 添付プロパティの概要 まとめ. はじめに. 依存プロパティは他の入力の値に基づいてプロパティの値を計算する方法を提供する為の 既存のプロパティの拡張です。 添付プロパティは任意のオブジェクトに対して設定可能な一種のグローバル プロパティを提供する為の 既存のプロパティの拡張です。. 混同厳禁. 依存プロパティの概要.

svein
Download Presentation

WPF 依存プロパティは すばらしい?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WPF依存プロパティはすばらしい? えムナウ(児玉宏之) MicrosoftMVPfor Visual-Developer C# 2005/01-2008/12

  2. アジェンダ • はじめに • 依存プロパティの概要 • 添付プロパティの概要 • まとめ

  3. はじめに • 依存プロパティは他の入力の値に基づいてプロパティの値を計算する方法を提供する為の 既存のプロパティの拡張です。 • 添付プロパティは任意のオブジェクトに対して設定可能な一種のグローバル プロパティを提供する為の 既存のプロパティの拡張です。 混同厳禁

  4. 依存プロパティの概要 • 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>

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

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

  7. 依存プロパティの概要 • どんな風な定義? public static readonly DependencyProperty CurrentProperty = DependencyProperty.Register( "Current", typeof(int), typeof(UserControl1)); • Currentプロパティ • Int 型 • UserControl1というクラスのプロパティ

  8. 依存プロパティの概要 public static readonly DependencyPropertyCurrentProperty =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 検証

  9. 依存プロパティデモ

  10. 添付プロパティの概要 • 自分の子供にプロパティを付加するもの • Grid.Row Grid.Column • DockPanel.Dock • 自分の子供とか関係なくプロパティを付加するもの • Validation.ErrorTemplate • Validation.HasErrorValidation.Errors

  11. 添付プロパティの概要 • なにができるの? • 親要素で定義されるプロパティについて、子要素がそれぞれ別の値を指定 • オブジェクトのそれぞれが、所有する型に対して共通の情報を報告

  12. 添付プロパティの概要 • どんな風な定義? public static readonly DependencyProperty Bool1Property =DependencyProperty.RegisterAttached("Bool1", typeof(bool), typeof(Attached1)); • Bool1プロパティ • bool 型 • Attached1というクラスのプロパティ

  13. 添付プロパティの概要 public static bool GetBool1(DependencyObject element) public static void SetBool1(DependencyObject element, bool value) • DependencyObjectに添付する • Bool 型の変数 げったーせったー

  14. 添付プロパティデモ

  15. まとめ • 依存プロパティはWPFにおける一般的なプロパティでWPFとやり取りをする機構をもっています。 • 添付プロパティはWPFにおいて子供の要素や関係ない要素にグローバルなプロパティを提供するものです。 混同厳禁

More Related