将DisplayName和Description指定给用户控件属性



DisplayName和Description属性被我的用户控件属性忽略,但Category没有
和这个问题差不多,只是在我的情况下,建议的答案不起作用。

我的代码:

[DisplayName("Custom String"),
Category("Custom Properties"),
Description("String to display.")]
public string CustomString
{
get { return customString; }
set { customString = value; }
}
private string customString;

"属性"窗口,显示只有"类别属性"在工作。

第2版--------------------

不同的webforms项目,用相同的代码(不同的值)从头开始创建的新用户控件。与以前的结果相同,只应用了"类别"。

public partial class AttributedUserControl : System.Web.UI.UserControl
{
[DisplayName("New Control Text"),
Category("New control Properties"),
Description("Text to show inside the user control.")]
public string TextString
{
get { return _TextString; }
set { _TextString = value; }
}
private string _TextString;
protected void Page_Load(object sender, EventArgs e)
{
}
}

  • Visual Studio Professional 2015-版本14.0.25431.01更新3
  • .NET Framework 4.7.03056

您发现了一个错误。我使用Visual Studio 2017创建了一个服务器控件和一个用户控件,发现System.ComponentModel.DescriptionAttribiute(即[Description("My Description")])不起作用。我还发现System.ComponentModel.DisplayName(即[DisplayName("My Description")])不起作用。当我说"不起作用"时,我的意思是属性网格不会像应该的那样在属性网格窗口的底部显示描述。无论将什么设置为"描述"属性,只有特性名称字符串本身才会显示在特性网格的描述区域中。

我建议将此问题发布到Microsoft。这很令人沮丧,但你没有做错什么。我在编写Winforms控件和设计器方面有着丰富的经验,这些属性在Winforms空间中发挥作用。

FWIW,其他属性(如[DefaultValue("Test")])也可以正常工作。

我希望我能报道更好的消息。如果你有资格的话,你可以接受这个答案,或者试着在这个问题上开始奖励。否则,我会邀请其他专家参与进来。

最新更新