代码之家  ›  专栏  ›  技术社区  ›  Akash Kava

如何在blend for silverlight的属性浏览器中显示附着的属性?

  •  1
  • Akash Kava  · 技术社区  · 16 年前

    我创建了两个自定义控件,它们的childresn在WPF的属性浏览器中正确显示附加属性,但在silverlight中,属性浏览器中没有显示任何附加属性。

    如何在silverlight中为附加属性添加设计时支持?

    2 回复  |  直到 16 年前
        1
  •  2
  •   Henrik Söderlund    16 年前

    看起来可能有一些属性可用于使自定义属性显示在设计器中:
    http://blogs.msdn.com/jnak/archive/2008/01/17/showing-attached-properties-in-the-cider-wpf-designer.aspx

    我还没有尝试过它,不确定它是否能与Silverlight一起工作。

        2
  •  0
  •   indigophoenix    9 年前

    Henrik's绝对适用于VS2015/Blend中的WPF。仅供参考,我添加了一些链接文章中的信息,因为很多次博客链接在几年后就消失了。

    附件属性BrowsablehenAttributePresentAttribute

    当选定项具有给定的属性时,属性浏览器中的 属性应用于它。如果该属性具有默认值,则 值也必须与默认值不同。

    在中选择下面的CustomLabel时要查找的属性 设计器中,属性浏览器将显示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

    此属性允许您指定在设计器中选择给定类型或从该类型派生的类型时显示附着的属性。选择任何栅格、衍生栅格、按钮或衍生按钮时,以下示例将显示附着的属性。

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

    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