如何在 silverlight 的 Blend 属性浏览器中显示附加属性?

发布于 2024-08-18 09:29:33 字数 122 浏览 4 评论 0原文

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

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

I created couple of custom controls and their childresn correctly shows the attached properties in Property Browser for WPF, but in silverlight none of the attached properties appear in Property Brower.

How to add design time support for attached properties in silverlight?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诠释孤独 2024-08-25 09:29:33

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

我还没有尝试过,不确定如果它可以与 Silverlight 一起使用。

Looks like there might be some attributes to work with to make custom properties appear in the designer:
http://blogs.msdn.com/jnak/archive/2008/01/17/showing-attached-properties-in-the-cider-wpf-designer.aspx

I have not tried it though, not sure if it will work with Silverlight.

鱼忆七猫命九 2024-08-25 09:29:33

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

AttachedPropertyBrowsableWhenAttributePresentAttribute

此属性允许您指定附加属性显示
当所选项目具有给定值时,在属性浏览器中向上
应用于它的属性。如果该属性有默认值,则
值也必须与默认值不同。

在上面的示例中,传入“MyCustomAttribute”作为
当在下面的 CustomLabel 中选择时要查找的属性
设计器中,属性浏览器将显示 ShowWhenCustomAttribute
附加财产,但它不会时
选择 CustomLabelNoCustomAttribute:

     

[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);
}

以下是 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

Henrik's definitely works for WPF in VS2015/Blend. Just for reference, I'm adding some of the info from the linked article because so many times links to blogs die after a number of years.

AttachedPropertyBrowsableWhenAttributePresentAttribute

This attribute allows you to specify that your attached property show
up in the Property Browser when the selected item has a given
attribute applied to it.  If the attribute has a default value, that
value also has to be different from the default value.

In the example above that passes in “MyCustomAttribute” as the
attribute to look for, when CustomLabel below is selected in the
designer, the Property Browser will show the ShowWhenCustomAttribute
attached property however it will not when
CustomLabelNoCustomAttribute is selected:

[MyCustomAttribute]
public class CustomLabel : Label
{
}

public class CustomLabelNoCustomAttribute : Label
{
}

AttachedPropertyBrowsableForChildrenAttribute

This attribute indicates that the attached property should be available for the children of the given control.  There are two main flavors for this attribute.  One that includes descendants and one that does not. As you might expect including descendants refers to including all children or simply the direct children of the control.

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

AttachedPropertyBrowsableForType

This attribute allows you to specify that your attached property show up when a given type or types derived from that type are selected in the designer.  The following sample would make your attached property show up when any Grid, derived Grid, Button or derived Button is selected.

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

And here are the MSDN doc links:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文