C# 如何停止设计器为用户控件上的公共属性生成代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29696/
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
How do you stop the Designer generating code for public properties on a User Control?
提问by John Hunter
How do you stop the designer from auto generating code that sets the value for public properties on a user control?
如何阻止设计器自动生成设置用户控件公共属性值的代码?
采纳答案by Erik Hellstr?m
Use the DesignerSerializationVisibilityAttribute on the properties that you want to hide from the designer serialization and set the parameter to Hidden.
对要从设计器序列化中隐藏的属性使用 DesignerSerializationVisibilityAttribute,并将参数设置为 Hidden。
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string Name
{
get;
set;
}
回答by Will Dean
Add the following attributes to the property in your control:
将以下属性添加到控件中的属性:
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
回答by peterincumbria
A slight change to Erik's answer I am using VS 2013.
对 Erik 的回答略有改动,我使用的是 VS 2013。
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new string Name {
get;
set;
}