[英]WPF custom control: How to assign the category “Text” to a property?
當“排列方式:類別”處於活動狀態時,某些本機WPF控件的屬性類別為“文本”,它們在屬性檢查器中列出。 但是當我嘗試使用WPF自定義控件的屬性設置此類別時
[Category("Text")]
這是行不通的。 該屬性未出現在任何類別中。 (在VS 2015中進行了測試。)
這符合System.ComponentModel.CategoryAttribute
不包含Text類別的事實。
但是,如何將屬性與“文本”類別相關聯?
編輯:為澄清起見,這是原始代碼中屬性實現的相關部分:
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
...
public static readonly DependencyProperty IsReadOnlyProperty;
...
[Browsable(true)]
[Category("Text")]
[Description("Gets or sets a value that indicates whether the text editing control is read-only to a user interacting with the control.")]
public bool IsReadOnly
{
get { return (bool)GetValue(IsReadOnlyProperty); }
set { SetValue(IsReadOnlyProperty, value); }
}
首先,請確保您使用的是依賴項屬性。 如果不是,請嘗試鍵入dependencyproperty,然后單擊選項卡(或輸入)。 然后定義其類型和名稱。
然后,您可能會找到以下代碼行並添加您的屬性,如下所示:
[Description("Your Description"), Category("Text")]
public string PropName {
get { return (string)GetValue(PropNameProperty); }
set { SetValue(PropNameProperty, value);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.