none
ADDING EVENTS TO CUSTOM BUSINESS TYPE CHECK BOX RRS feed

  • Question

  • Hi,

    I have created a business type to replace the shortinteger, and use a Checkbox on the user interface. Below is the XAML for the control:

    <UserControl x:Class="MyTypes.Presentation.Controls.MBooleanControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <CheckBox Name="er" Checked="CheckBox_Checked"  Unchecked="CheckBox_Unchecked" IsChecked="{Binding Value,Mode=TwoWay}" />
    </UserControl>

    and below is the code:

        public partial class MBooleanControl :UserControl
        {
            public MBooleanControl()
            {
                InitializeComponent();
            }
            public event CheckedEventHandler IsChecked;
            public event UnCheckedEventHandler Unchecked;
            public delegate void CheckedEventHandler(object sender, EventArgs e);
            public delegate void UnCheckedEventHandler(object sender, EventArgs e);
    
    
            private void CheckBox_Checked(object sender, RoutedEventArgs e)
            {
                OnChecked(EventArgs.Empty);
            }
            protected virtual void OnChecked(EventArgs e)
            {
                if (IsChecked != null)
                    IsChecked(this, e);
            }
            protected virtual void OnUnchecked(EventArgs e)
            {
                if (Unchecked != null)
                    Unchecked(this, e);
            }
    
            private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
            {
                OnUnchecked(EventArgs.Empty);
            }
        }

    I wanted it to behave like the default checkbox, with events for checked and unchecked, and am unable to make the events work. Please someone help me.

    Thanks in advance


    private


    • Edited by Kilonzo Monday, December 8, 2014 10:45 AM
    Monday, December 8, 2014 6:44 AM

All replies