using System.Drawing; namespace System.Windows.Forms { public class ToggleButtonBase : ButtonBase { protected new System.Windows.Controls.Primitives.ToggleButton control { get; private set; } public bool Checked { get => control.IsChecked ?? false; set => control.IsChecked = value; } public CheckState CheckState { get { return control.IsChecked == true ? CheckState.Checked : (control.IsChecked == false ? CheckState.Unchecked : CheckState.Indeterminate); } set { control.IsChecked = value == CheckState.Checked ? true : (value == CheckState.Unchecked ? false : null); } } public ContentAlignment CheckAlign { get; set; } // not supported public bool ThreeState { get => control.IsThreeState; set => control.IsThreeState = value; } public event EventHandler CheckedChanged; protected virtual void OnCheckedChanged(EventArgs e) => CheckedChanged?.Invoke(this, e); public override void Select() => Checked = true; protected void SetControl(System.Windows.Controls.Primitives.ToggleButton control) { base.SetControl(control); this.control = control; control.Checked += (sender, e) => OnCheckedChanged(e); control.Unchecked += (sender, e) => OnCheckedChanged(e); TextAlign = System.Drawing.ContentAlignment.MiddleLeft; } } }