user8390205
user8390205

Reputation: 13

How do I prevent Visual Studio from firing events on the designer?

I've got a user control which is supposed to fire an event when the visibility or the enable status changes.

My problem is the events fire on Visual Studio's designer too, which is irritating since during design they act in an unexpected behaviour.

How can I prevent that?

Upvotes: 1

Views: 345

Answers (1)

Michael
Michael

Reputation: 2113

Add this property to your (base) class and check its value in the RaiseEventXYZ or FireEventXYZ methods...

public class MyClass
{
    public bool IsDesignMode { get;private set; }
    public MyClass()
    {
        IsDesignMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime;
    }
}

Upvotes: 1

Related Questions