Lar*_*ens 7

可浏览意味着设计人员(如Visual Studio的WPF设计人员名为Cider)会在设计器中显示该属性.由于附加属性不是类型的实际属性,并且可以应用于几乎类型,因此设计者很难知道何时显示或不显示属性.这些属性是开发人员让设计者知道应该在设计器中显示某个附加属性的一种方式.换句话说:可浏览.此特定属性允许设计人员知道此附加属性应该可以在应用了指定属性的类型上浏览.

附属物:

public class WhenAttributePresentTestControl : Grid
{
    public static readonly DependencyProperty ShowWhenCustomAttributePresentProperty = DependencyProperty.RegisterAttached(
      "ShowWhenCustomAttributePresent",
      typeof(int),
      typeof(WhenAttributePresentTestControl));

    public static void SetShowWhenCustomAttributePresent(UIElement element, int value)
    {
        element.SetValue(ShowWhenCustomAttributePresentProperty, value);
    }

    [AttachedPropertyBrowsableWhenAttributePresentAttribute(typeof(MyCustomAttribute))]
    public static int GetShowWhenCustomAttributePresent(UIElement element)
    {
        return (int)element.GetValue(ShowWhenCustomAttributePresentProperty);
    }
}
Run Code Online (Sandbox Code Playgroud)

用法示例:

[MyCustomAttribute]
public class CustomLabel : Label
{
}

public class CustomLabelNoCustomAttribute : Label
{
}
Run Code Online (Sandbox Code Playgroud)

设计器将在CustomLabel的属性编辑器中显示ShowWhenCustomAttributePresent附加属性,但不会显示CustomLabelNoCustomAttribute.

资料来源: http ://blogs.msdn.com/jnak/archive/2008/01/17/showing-attached-properties-in-the-cider-wpf-designer.aspx

实际用法: 我在使用Reflector的.Net框架中找不到此属性的任何用法.

有趣的旁注:显然它也是.Net 3.0框架的最长类型名称