我有一个继承自 UserControl 的用户控件。这是一个按钮,因此我尝试使用像真实按钮一样的 Text 属性来更改按钮中的文本,而不是像 _Text 这样命名我自己的文本。我有以下代码,但它不起作用(即它没有显示在属性窗口中)。标签的名称是ContentPresenter
public override string Text
{
get
{
return ContentPresenter.Text;
}
set
{
ContentPresenter.Text = value;
}
}
UserControl 付出了巨大的努力来隐藏 Text 属性。从元数据来看:
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Bindable(false)]
public override string Text { get; set; }
您可以通过覆盖代码中的这些属性来使其可见:
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[EditorBrowsable(EditorBrowsableState.Always)]
[Bindable(true)]
public override string Text
{
get { return ContentPresenter.Text; }
set { ContentPresenter.Text = value; }
}
我不能保证这足以使其发挥作用,但很可能是这样。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)