How to get & ldquo; this & rdquo; scope in the custom control constructor in WPF

advertisements

I have extended the WPF Checkbox and built a Customcontrol, so I can add features to the checkbox.

My constructor looks like this

static MyCheckBox()
{
    DefaultStyleKeyProperty.OverrideMetadata(
        typeof(MyCheckBox), new FrameworkPropertyMetadata(typeof(MyCheckBox)));
}

Now I want to add an handler:

Validation.AddErrorHandler(this, OnValidationError);

But I don't have the this scope in the static constructor. How can I solve that?

Basically what I am trying to do is, to set an dependency property I created (IsValid9 to true or false, when the Validation.Error Event gets called. Therefore I need to register the handler.


Add a public non-static constructor:

public MyCheckBox()
{
    Validation.AddErrorHandler(this, OnValidationError);
}