views:

31

answers:

1

Something like:

<DesignTimeHidden()> _
Private Sub UserControl_IsVisibleChanged(sender As Object, _
    e As DependencyPropertyChangedEventArgs) Handles Me.IsVisibleChanged

End Sub
+1  A: 

It sounds like you want a method which, if called at design-time, is ignored, but can still be called at run-time.

This is not possible with an attribute. However your method code can check if it is being called at design time and return without doing anything. How you do this depends on your environment.

  • For components such as WinForms or ASP.NET controls, check the DesignMode property (note this is not set until after construction, so is not reliable in the constructor or methods called from the constructor).

  • For WPF components, call DesignerProperties.IsInDesignMode(this).

itowlson
No.What I meant was that the VS should skip that method on design-time.
Shimmy
Okay, I think I see what you're after. Updated.
itowlson
I have a problem, I am trying to use UserControl, in run-time it works like a charm, in design time it says "Could not create an instance of 'MyUserControl'". it sux, I am struggling with this to much...Thanks for your effort, I think it's irrelevant since the exception is thrown by the InitializeComponent method, I tried to remove the method and still no design-time support.
Shimmy
The exception is thrown *within* InitializeComponent? Sounds like there's some other issue going on then... might be worth posting a separate question with the details and the exception info.
itowlson
I don't know what the exception is, I just know that I am trying to use a UserControl in my code doing <src:MyUserControl/> and the designer says: "Unable to create an instance of 'MyUserControl'", but in the designer of the usercontrol itself everything works good.
Shimmy
Put a (temporary) try block around the MyUserControl constructor, and in the catch clause display or log the exception details.
itowlson