Visual Studio 自动将我的属性之一更改为 null
我怎样才能让它退后并留下财产呢?
这是属性:
/// <summary>
/// Collection of SednaTreeViewItems used to populate the SednaTreeView.
/// </summary>
public IEnumerable<SednaTreeViewItem> TreeNodes
{
get { return treeNodes; }
set
{
ultraTree.Nodes.Clear();
treeNodes = value;
foreach (var item in treeNodes)
{
UltraTreeNode node = new UltraTreeNode(item.ValueMember, item.DisplayMember);
ultraTree.Nodes.Add(node);
}
}
}
每当我在设计器中更改另一个属性时,它似乎都会将此属性检测为属性并将其设置为 null。我可以使用装饰器让它忽略该属性吗?
How can I tell it to back off and leave the property alone?
Here's the property:
/// <summary>
/// Collection of SednaTreeViewItems used to populate the SednaTreeView.
/// </summary>
public IEnumerable<SednaTreeViewItem> TreeNodes
{
get { return treeNodes; }
set
{
ultraTree.Nodes.Clear();
treeNodes = value;
foreach (var item in treeNodes)
{
UltraTreeNode node = new UltraTreeNode(item.ValueMember, item.DisplayMember);
ultraTree.Nodes.Add(node);
}
}
}
Whenever I'm in the designer and change another property it seems to detect this one as a Property and set it to null. Is there a decorator I can use to make it ignore the property?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修复方法是
DesignerSerializationVisibility
属性,这会阻止设计器序列化属性的值(即,向Designer.cs
文件中添加垃圾)。它看起来像这样:
The fix is the
DesignerSerializationVisibility
attribute, which prevents the designer from serializing the value of the property (i.e., adding junk to yourDesigner.cs
file).It looks like this:
您可以添加一个属性以使其在设计器中不可“浏览”。
http://msdn.microsoft.com/en-us/ Library/system.componentmodel.browsableattribute.aspx
Browsable 不太工作,但还有另一个问题提供了另一个属性。
如何让 WinForm Designer 完全忽略自定义控件上的属性?
You can add an attribute to make it not "Browsable" in the designer.
http://msdn.microsoft.com/en-us/library/system.componentmodel.browsableattribute.aspx
Browsable didn't quite work, but there is another question that offers another attribute.
How do I get the WinForm Designer to totally ignore a property on a custom control?