为什么我的自定义控件的Text属性在属性窗口中显示出来? [英] Why won't my Custom Control's Text property show up in the Properties window?

查看:311
本文介绍了为什么我的自定义控件的Text属性在属性窗口中显示出来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从用户控件继承的用户控件。这是一个按钮,所以我试图在按钮上的文本,改变,能够通过使用Text属性像真正的按钮,而不是命名我自己喜欢_text。我有以下的代码,但它不工作(即它不会在属性窗口中显示出来)。标签的名称是ContentPresenter

 公众覆盖字符串文本
{
得到
{
返回ContentPresenter.Text;
}

{
ContentPresenter.Text =价值;
}
}


解决方案

用户控件去显著努力隐藏Text属性。从元数据:

  [可浏览(假)] 
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
[EditorBrowsable(EditorBrowsableState.Never)
[可绑定(假)]
公众覆盖字符串文本{搞定;组; }

您可以使其可见通过覆盖在你的代码的那些属性:

  [可浏览(真)] 
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)
[EditorBrowsable(EditorBrowsableState.Always)]
〔可绑定(真)]
公众覆盖字符串文本
{
{返回ContentPresenter.Text; }
集合{ContentPresenter.Text =价值; }
}



我不看好这足以令它的工作,但它可能是。


I have a user control that inherits from UserControl. It's a button so I'm trying to make the text in the button, change-able by using the Text property like the real buttons, instead of naming my own like _Text. I have the following code but it doesn't work (ie it doesn't show up in the Property Window). The name of the label is ContentPresenter

public override string Text
{
    get
    {
        return ContentPresenter.Text;
    }
    set
    {
        ContentPresenter.Text = value;
    }
}

解决方案

UserControl goes to significant effort to hide the Text property. From the metadata:

    [Browsable(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    [Bindable(false)]
    public override string Text { get; set; }

You can make it visible by overriding those attributes in your code:

    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [Bindable(true)]
    public override string Text 
    { 
        get { return ContentPresenter.Text; } 
        set { ContentPresenter.Text = value; } 
    } 

I'm not promising that's enough to make it work, but it probably is.

这篇关于为什么我的自定义控件的Text属性在属性窗口中显示出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆