Completed
Last Updated: 15 Aug 2017 10:28 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 23 Mar 2017 13:27
Category: Buttons
Type: Bug Report
1
FIX. RadCheckBox - after creating a custom RadCheckBoxElement several events don't fire any more
The same case is valid for RadToggleButton as well.

To reproduce: use the following custom RadCheckBox. You will notice that the ToggleStateChanging, ToggleStateChanged, PropertyChanged, CheckStateChanging, CheckStateChanged won't fire anymore:

public class MyCheckBoxElement : RadCheckBoxElement
{
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadCheckBoxElement);
        }
    }
}

public class MyCheckBox : RadCheckBox
{
    protected override RadButtonElement CreateButtonElement()
    {
        return new MyCheckBoxElement();
    }

    public override string ThemeClassName
    {
        get
        {
            return typeof(RadCheckBox).FullName;
        }
    }
}

Workaround:

public class MyCheckBoxElement : RadCheckBoxElement
{
    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            return;
        }

        base.OnKeyDown(e);
    }

    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadCheckBoxElement);
        }
    }
}

public class MyCheckBox : RadCheckBox
{
    protected override RadButtonElement CreateButtonElement()
    {
        MyCheckBoxElement checkBox = new MyCheckBoxElement();
        checkBox.ToggleStateChanging += new StateChangingEventHandler(ButtonElement_ToggleStateChanging);
        checkBox.ToggleStateChanged += new StateChangedEventHandler(ButtonElement_ToggleStateChanged);
        checkBox.PropertyChanged += new PropertyChangedEventHandler(res_PropertyChanged);
        checkBox.CheckStateChanging += new CheckStateChangingEventHandler(res_CheckStateChanging);
        checkBox.CheckStateChanged += new EventHandler(res_CheckStateChanged);
        return checkBox;
    }

    private void res_CheckStateChanged(object sender, EventArgs e)
    {
        base.OnCheckStateChanged(e);
    }

    private void res_CheckStateChanging(object sender, CheckStateChangingEventArgs args)
    {
        base.OnCheckStateChanging(args);
    }

    private void res_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "IsChecked")
        {
            base.OnNotifyPropertyChanged("IsChecked");
        }
    }

    private void ButtonElement_ToggleStateChanged(object sender, StateChangedEventArgs args)
    {
        base.OnToggleStateChanged(args);
        base.OnNotifyPropertyChanged("Checked");
        base.OnNotifyPropertyChanged("CheckState");
        base.OnNotifyPropertyChanged("ToggleState");
    }

    private void ButtonElement_ToggleStateChanging(object sender, StateChangingEventArgs args)
    {
        base.OnToggleStateChanging(args);
    }

    public override string ThemeClassName
    {
        get
        {
            return typeof(RadCheckBox).FullName;
        }
    }
}
0 comments