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 injecte开发者_如何学JAVAd at runtime ...
You're probably getting an exception when VS tries to generate the designer code.
Attach a second copy of VS to the designer, turn on Break On Exceptions, and see what's going on.
So the exception is thrown by the Designer of the Windows form that contains the UserControl:
Instances of this error (1)
- Infrastructure.BaseModule.MYWindow.Designer.cs Line:108 Column:1 Hide Call Stack
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
精彩评论