日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
WPF附加屬性相關(guān)用途介紹

我們通過對(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 方法的返回值來定義此字段。例如:

 
 
 
  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)容:)


分享文章:WPF附加屬性相關(guān)用途介紹
本文網(wǎng)址:http://www.5511xx.com/article/cccoses.html