2015-08-23 41 views
2

在之前的XAML技術中,您可以將CategoryAttribute添加到依賴項屬性中,並且它將顯示在Blend和Visual Studio的屬性窗口中。如何將我的控件的屬性分類到Blend和Visual Studio設計器的適當部分?

例如,我想爲自定義控件添加一個新的Brush屬性,並使其顯示在「外觀」類別下。

[Category("Appearance")] 
public Brush MyAwesomeBrush { get {...} set {...} } 

有沒有辦法爲Windows商店應用程序(Win8/Win10/Phone/etc)做到這一點?

回答

1

你可以做,如果你真的想。

添加下面的類到您的項目(保留命名空間,一切都正是這樣):

namespace System.ComponentModel 
{ 
    [AttributeUsage(AttributeTargets.All)] 
    public class CategoryAttribute : Attribute 
    { 
     public CategoryAttribute(string category) 
     { 
      Category = category; 
     } 

     public string Category { get; private set; } 

     public override bool Equals(object obj) 
     { 
      if (obj == this) 
       return true; 

      var other = obj as CategoryAttribute; 
      return other != null && other.Category == Category; 
     } 

     public override int GetHashCode() 
     { 
      return Category.GetHashCode(); 
     } 
    } 
} 

使用這種方式:

how to use it

而且tada.wav,它的工作原理:)

blend screenshot

+0

Excellen牛逼!這樣可行!我們可以對此做些什麼其他屬性? – Laith

+1

嗯,我猜如果Blend可以欺騙使用這一個,這些大部分都可能工作以及https://msdn.microsoft.com/en-us/library/tk67c2t8.aspx –

+1

是的。 'DescriptionAttribute'也適用。與上面相同的代碼。我會嘗試更多。 – Laith

0

this後,它不支持在Windows Store應用程序等

相關問題