简体   繁体   English

如何将嵌套的设计时属性添加到用户控件?

[英]How can I add a nested design-time property to a user control?

I have a user control that contains a number of panel controls. 我有一个包含多个面板控件的用户控件。 The user control has logic to set the visibility of each panel, based on the values of some variables contained in the user control. 用户控件具有根据用户控件中包含的某些变量的值来设置每个面板的可见性的逻辑。

I would like to enhance this functionality by adding the following enumeration: 我想通过添加以下枚举来增强此功能:

public enum Visibility
{
    Default,
    Always,
    Never
}

where Default would use the current logic to set the panel's visibility, but Always would (obviously) make the panel always visible, and Never would always hide the panel. 其中“ Default将使用当前逻辑来设置面板的可见性,但“ Always将(显然)使面板始终可见,而“ Never将始终隐藏面板。

I would also like to add a "nested" design-time property named something like PanelVisiblity that the developer could expand, and see the panel names listed below, and allow them to assign a value from the Visibility enumeration for each. 我还想添加一个“嵌套的”设计时属性,该名称类似于PanelVisiblity ,开发人员可以对其进行扩展,并看到下面列出的面板名称,并允许他们从Visibility枚举中为每个面板分配一个值。

If I add properties like this: 如果我添加这样的属性:

public partial class MyControl : UserControl
{
    public Visibility ActivePanel { get; set; }
    public Visibility CodePanel { get; set; }
}

the ActivePanel and CodePanel properties appear in the Properties window in Visual Studio, and I can set them to one of the three values in the enum. ActivePanelCodePanel属性出现在Visual Studio中的属性窗口中,我可以将它们设置为在枚举的三个值中的一个。 However, when I refactored my code to try to create a nested property like this: 但是,当我重构代码以尝试创建如下嵌套属性时:

public partial class MyControl : UserControl
{
    public class PanelVisibility
    {
        public enum Visibility
        {
            Default,
            Always,
            Never
        }

        public Visibility ActivePanel { get; set; }
        public Visibility CodePanel { get; set; }
    }
}

I do not get an expandable PanelVisiblity property, I get a disabled Visiblity property, where the value is the namespace of class, plus 'PanelVisibility'. 我没有得到可扩展的PanelVisiblity属性,没有得到禁用的Visiblity属性,其中值是类的名称空间,加上“ PanelVisibility”。

I have Googled a number of variations in phrasing this search, but have not been able to find anything like what I'm looking for. 在搜索词组中,我用Google搜索了许多变体,但找不到与我要找的东西相似的东西。

Any direction would be greatly appreciated. 任何方向将不胜感激。

It seems that you are looking for the same functionality as a DockPanel offers. 似乎您正在寻找与DockPanel提供的功能相同的功能。

I'd suggest you that instead of re-inventing the wheel you should use one the available implementations to you such as : 我建议您不要重新发明轮子,而应该使用一种可用的实现方式,例如:

http://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel.aspx http://msdn.microsoft.com/zh-CN/library/system.windows.controls.dockpanel.aspx

http://dockpanel2012.codeplex.com/ http://dockpanel2012.codeplex.com/

https://github.com/dockpanelsuite/dockpanelsuite https://github.com/dockpanelsuite/dockpanelsuite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM