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

314 Views Asked by At

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?

1

There are 1 best solutions below

1
Michael On

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;
    }
}