Changes in my userControl are erased when I rebuild in Visual Studio (designer view)

送分小仙女□ 提交于 2019-12-24 00:56:16

问题


This is my navigationItem.cs user control:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Uboldi.Helpers;

namespace Uboldi
{
    public partial class NavigationItem : UserControl
    {
        public bool IsSelected { get; set; }
        private string _linkText = String.Empty;
        [Browsable(true)]
        public string LinkText
        {
            get { return this._linkText; }
            set
            {
                this._linkText = value;
                RefreshDisplay();
            }
        }

        public NavigationItem()
        {
            InitializeComponent();
            RefreshDisplay();
        }

        private void RefreshDisplay()
        {
            if (IsSelected)
                this.BackColor = CustomizationHelper.GetSecondaryColor();
            else
                this.BackColor = CustomizationHelper.GetPrimaryColor();

            lblText.Text = Text;
        }
    }
}

My intention is to use this in another usercontrol called NavigationBar.

While I CAN see the LinkText attribute of the NavigationItem.cs class, when I change it from the properties pane, a warning pops up:

Warning 1 You must rebuild your project for the changes to Uboldi.LeftNavigationbar to show up in any open designers.

Fair enough, I rebuild, and then the changes I just typed in are gone!

Any ideas why?

Thank you for your time.


回答1:


Perhaps your changes are not persisted by the designer.

Did you try using DesignerSerializationVisibilityAttribute?

http://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibilityattribute.aspx




回答2:


This is old but doesn't have an answer. Here is what I found that works. Hopefully this helps someone else.

[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Description("Test text displayed in the link"), Category("Data")]
public string LinkText
{
     get { return this._linkText; }
     set
     {
         this._linkText = value;
         RefreshDisplay();
     }
}


来源:https://stackoverflow.com/questions/4788818/changes-in-my-usercontrol-are-erased-when-i-rebuild-in-visual-studio-designer-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!