簡體   English   中英

為什么某些控件屬性在Visual Studio設計器中顯示,而其他控件屬性沒有?

[英]Why are certain control properties shown in the Visual Studio designer, and others not?

以我的navigationItem用戶控件:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Uboldi.Helpers;

namespace Uboldi
{
    public partial class NavigationItem : UserControl
    {
        public bool IsSelected { get; set; }
        public string Text { get; set; }

        public NavigationItem()
        {
            InitializeComponent();
            RefreshDisplay();
        }

        private void RefreshDisplay()
        {
            if (IsSelected)
                this.BackColor = CustomizationHelper.GetSecondaryColor();
            else
                this.BackColor = CustomizationHelper.GetPrimaryColor();            
        }
    }
}

在Visual Studio中,我可以看到IsSelected屬性,但看不到Text屬性。 在此處輸入圖片說明

有什么原因嗎?

Text屬性是從UserControl繼承的。 在隱藏的地方,用戶控件沒有任何有意義的文本顯示方式。 您必須再次繼承它,並關閉所有使其隱藏的屬性。 像這樣:

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

您需要使用BrowsableAttribute在設計時屬性列表中標記要顯示的屬性。

[Browsable(true)]
public bool Text { get; set; } 

猜測是IsSelected屬性是繼承的,並設置了此屬性。 我可能已離開,因為我認為編譯器會警告您,如果是這種情況,您將隱藏繼承的屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM