开发者

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

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!

An开发者_JAVA技巧y ideas why?

Thank you for your time.


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


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();
     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜