Windows Form UserControl design time properties
Posted
by
Raffaeu
on Stack Overflow
See other posts from Stack Overflow
or by Raffaeu
Published on 2010-12-21T13:49:41Z
Indexed on
2010/12/21
13:54 UTC
Read the original article
Hit count: 181
c#
|design-time
I am struggling with a UserControl. I have a UserControl that represent a Pager and it has a Presenter object property exposed in this way:
[Browsable(false)]
[DesignSerializationAttribute(DesignSerializationAttribute.Hidden)]
public object Presenter { get; set; }
The code itself works as I can drag and drop a control into a Windows From without having Visual Studio initializing this property. Now, because in the Load event of this control I call a method of the Presenter that at run-time is null ... I have introduced this additional code:
public override void OnLoad(...)
{
if (this.DesignMode)
{
base.OnLoad(e);
return;
}
presenter.OnViewReady();
}
Now, every time I open a Window that contains this UserControl, Visual Studio modifies the Windows designer code. So, as soon as I open it, VS ask me if I want to save it ... and of course, if I add a control to the Window, it doesn't keep the changes ... As soon as I remove the UserControl Pager the problem disappears ... How should I tackle that in the proper way? I just don't want that the presenter property is initialized at design time as it is injected at runtime ...
© Stack Overflow or respective owner