自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

WPF附加屬性相關(guān)用途介紹

開發(fā) 開發(fā)工具
WPF附加屬性可以通過(guò)不同的子元素幫助我們?cè)诟冈刂卸x的屬性指定唯一值。在這篇文章中我們將會(huì)幫助大家詳細(xì)介紹相關(guān)概念。

我們通過(guò)對(duì)WPF的深入學(xué)習(xí),可以知道,WPF中的屬性可以分為兩種,一種是依賴屬性而另外一種則是附加屬性。我們?cè)谶@里將會(huì)重點(diǎn)介紹WPF附加屬性。#t#

WPF附加屬性是允許不同的子元素為 實(shí)際在父元素中定義的屬性指定***值。例如:

  1. < DockPanel> 
  2. < CheckBox DockPanel.
    Dock
    ="Top">Hello
    < /CheckBox> 
  3. < /DockPanel> 

Dock不是CheckBox的屬性,而是定義在DockPanel中的。

用代碼使用:

  1. DockPanel myDockPanel = 
    new DockPanel();  
  2. CheckBox myCheckBox = 
    new CheckBox();  
  3. myCheckBox.Content = 
    "Hello";  
  4. myDockPanel.Children.
    Add(myCheckBox);  
  5. DockPanel.SetDock
    (myCheckBox, Dock.Top); 

如何創(chuàng)建WPF附加屬性

1. 聲明一個(gè) DependencyProperty 類型的 public static readonly 字段,將附加屬性定義為一個(gè)依賴項(xiàng)屬性。

2. 使用 RegisterAttached 方法的返回值來(lái)定義此字段。例如:

  1. public class OwerClass : 
    DependencyObject  
  2. {  
  3. public static string 
    GetAttachedPropertyName
    (DependencyObject obj)  
  4. {  
  5. return (string)obj.GetValue
    (AttachedPropertyNameProperty);  
  6. }  
  7. public static void SetAttached
    PropertyName(DependencyObject 
    obj, string value)  
  8. {  
  9. obj.SetValue(AttachedProperty
    NameProperty, value);  
  10. }  
  11. public static readonly 
    DependencyProperty 
    Attached
    PropertyNameProperty
     =  
  12. DependencyProperty.RegisterAttached
    ("AttachedPropertyName", 
    typeof(string), typeof(OwerClass), 
    new UIPropertyMetadata(0));  

WPF附加屬性小提示:

可以利用VS2008智能提示:在class里面輸入propa,然后按Tab 自動(dòng)生成基本內(nèi)容:)

責(zé)任編輯:曹凱 來(lái)源: 博客園
相關(guān)推薦

2009-12-23 17:18:45

WPF Attache

2009-12-29 10:11:56

WPF布局屬性

2009-12-29 13:29:28

WPF Depende

2009-12-25 11:04:51

WPF Border

2010-02-24 16:52:59

WCF支持WebGet

2009-12-23 09:26:56

ADO.NET屬性

2011-08-16 15:04:15

交換機(jī)快速啟動(dòng)

2010-01-11 15:43:06

VB.NET類屬性

2009-12-29 16:02:48

ADO.NET新特性

2023-09-15 11:49:33

wpf依賴屬性

2009-12-28 13:47:35

WPF對(duì)話框

2009-12-28 17:48:01

WPF界面布局

2009-12-28 17:54:49

WPF嵌入式資源

2009-12-24 15:22:10

WPF繼承自定義窗口

2009-12-24 16:46:42

ADO Connect

2009-12-28 14:51:59

WPF元素樹

2014-12-09 10:48:12

openstacknovaNUMA

2009-12-21 13:59:03

ADO.NET特性

2010-03-30 09:04:26

Silverlight依賴屬性附加屬性

2009-12-23 11:24:42

WCF附加屬性
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)