C# 用户控件属性设计器属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
User Control Property Designer Properties
提问by Adam Haile
For a C# UserControl on Windows Mobile (though please answer if you know it for full Windows...it might work) how do you change what shows up in the Designer Properties window for one of the Control's public Properties. For example:
对于 Windows Mobile 上的 C# 用户控件(不过,如果您知道完整的 Windows,请回答......它可能有效)您如何更改控件的公共属性之一的设计器属性窗口中显示的内容。例如:
private Color blah = Color.Black;
public Color Blah
{
get { return this.blah; }
set { this.blah = value; }
}
This shows up for the control, but it's in the "Misc" category and has no description or default value. I've tried using the settings in System.ComponentModel like "DesignerCategory", such as:
这显示为控件,但它在“杂项”类别中,没有描述或默认值。我尝试使用 System.ComponentModel 中的设置,如“DesignerCategory”,例如:
[DesignerCategory("Custom")]
But says this is only valid for class declarations... could've sworn it was the System.ComponentModel items I used before...
但是说这仅对类声明有效......可以发誓它是我之前使用的 System.ComponentModel 项目......
Update:
更新:
@John said:
@约翰说:
DesignerCatogy is used to say if the class is a form, component etc.
Try this:
[Category("Custom")]
DesignerCatogy 用于说明类是否是表单、组件等。
尝试这个:
[类别(“自定义”)]
Is there a particular namespace I need to use in order to get those? I've tried those exactly and the compiler doesn't recognize them.
我是否需要使用特定的命名空间来获取这些命名空间?我已经完全尝试过,但编译器无法识别它们。
In .NETCF all I seem to have available from System.ComponentModel is:
在 .NETCF 中,我似乎可以从 System.ComponentModel 获得的是:
DataObject,
DataObjectMethod,
DefaultValue,
DesignerCategory,
DesignTimeVisible,
EditorBrowsable
The only one it doesn't scream at is EditorBrowsable
它唯一不尖叫的是 EditorBrowsable
采纳答案by Rob Cooper
Is this of use to you? I am not into CF development, but it looks like you need to add some XML metadata to enable it:
这对你有用吗?我不参与 CF 开发,但看起来您需要添加一些 XML 元数据才能启用它:
Interesting read.. Looks like a lot of design time support was stripped out of CF because you dont design them on the devices.. Which seems kinda weird to me.. Cant imagine using a handheld as a development rig!
有趣的阅读.. 看起来很多设计时支持从 CF 中剥离出来,因为你没有在设备上设计它们.. 这对我来说似乎有点奇怪.. 无法想象使用手持设备作为开发设备!
Scroll down about half way for the good stuff ;)
向下滚动大约一半的好东西;)
回答by John
DesignerCategory
is used to say if the class is a form, component etc.
DesignerCategory
用于表示类是否是表单、组件等。
For full windows the attribute you want is:
对于完整的窗口,您想要的属性是:
[System.ComponentModel.Category("Custom")]
and for the description you can use [System.ComponentModel.Description("This is the description")]
对于您可以使用的描述 [System.ComponentModel.Description("This is the description")]
To use both together:
两者一起使用:
[System.ComponentModel.Category("Custom"),System.ComponentModel.Description("This is the description")]
However this is part of system.dll
which may be different for windows mobile.
然而,这是其中的一部分,system.dll
对于 windows mobile 可能有所不同。
回答by Pat O
The article does not suggest that anyone is designing ON the device. However, when you create a Compact Framework project, the compact framework (for your desktop PC) is used to handle design time rendering. If you think about it that is what you expect. The same framework (or nearly so) is used to do the rendering both on your PC at design time and later on the device at runtime. The issue is that the design time attributes were not added to the compact framework (I assume to reduce the size).
这篇文章并不暗示任何人在设备上进行设计。但是,当您创建 Compact Framework 项目时,将使用 Compact Framework(用于您的台式机)来处理设计时呈现。如果您考虑一下,那就是您的期望。相同的框架(或几乎如此)用于在设计时在您的 PC 上以及稍后在运行时在设备上进行渲染。问题是设计时属性没有添加到紧凑型框架中(我假设是为了减小尺寸)。