2010-01-18 59 views

回答

0

Henrik絕對適用於VS2015/Blend中的WPF。僅供參考,我在鏈接的文章中添加了一些信息,因爲很多次博客鏈接在數年後都會死亡。

AttachedPropertyBrowsableWhenAttributePresentAttribute

這個屬性允許你指定你的附加屬性顯示 了在屬性瀏覽器時所選擇的項目已申請將其定 屬性。如果該屬性具有默認值,則該值也必須不同於默認值。

在上面的例子通過在「MyCustomAttribute」作爲 屬性查找,當CustomLabel下面在 設計者選擇,在屬性瀏覽器將但是它不會當 CustomLabelNoCustomAttribute是顯示ShowWhenCustomAttribute 附加屬性選自:

[MyCustomAttribute] 
public class CustomLabel : Label 
{ 
} 

public class CustomLabelNoCustomAttribute : Label 
{ 
} 

AttachedPropertyBrowsableForChildrenAttribute

此屬性指示附加屬性應該可用於給定控件的子項。這個屬性有兩種主要的風味。一個包含後代,另一個不包含後代。正如你可能期望的那樣,包括後代是指包括所有的孩子或者僅僅是控制的直接子女。

[AttachedPropertyBrowsableForChildrenAttribute(IncludeDescendants=true)] 
public static int GetShowForChildrenDeep(UIElement element) 
{ 
    return (int)element.GetValue(ShowForChildrenDeepProperty); 
} 

AttachedPropertyBrowsableForType

這個屬性允許您指定當該類型派生給定的一種或多種類型的設計師選擇您的附加屬性顯示出來。下面的示例將使您的附加屬性在任何Grid,派生的Grid,Button或派生的Button被選中時顯示。

[AttachedPropertyBrowsableForType(typeof(Grid))] 
[AttachedPropertyBrowsableForType(typeof(Button))] 
public static int GetShowForTypes(UIElement element) 
{ 
    return (int)element.GetValue(ShowForTypesProperty); 
} 

這裏是MSDN文檔鏈接:

https://msdn.microsoft.com/en-us/library/system.windows.attachedpropertybrowsableforchildrenattribute(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.windows.attachedpropertybrowsablefortypeattribute(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/system.windows.attachedpropertybrowsablewhenattributepresentattribute(v=vs.110).aspx