Visual Studio 自动将我的属性之一更改为 null

发布于 2024-11-25 20:24:52 字数 604 浏览 0 评论 0原文

我怎样才能让它退后并留下财产呢?

这是属性:

/// <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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不奢求什么 2024-12-02 20:24:53

修复方法是 DesignerSerializationVisibility 属性,这会阻止设计器序列化属性的值(即,向 Designer.cs 文件中添加垃圾)。

它看起来像这样:

using System.ComponentModel;

/// <summary>
/// Collection of SednaTreeViewItems used to populate the SednaTreeView.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
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);
        }
    }
}

The fix is the DesignerSerializationVisibility attribute, which prevents the designer from serializing the value of the property (i.e., adding junk to your Designer.cs file).

It looks like this:

using System.ComponentModel;

/// <summary>
/// Collection of SednaTreeViewItems used to populate the SednaTreeView.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
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);
        }
    }
}
旧城空念 2024-12-02 20:24:53

您可以添加一个属性以使其在设计器中不可“浏览”。

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文