using System.Windows.Media; namespace System.Windows.Forms { public class CheckBox : ToggleButtonBase { private static System.Windows.Controls.ControlTemplate toggleButtonTemplate = (System.Windows.Controls.ControlTemplate)System.Windows.Markup.XamlReader.Parse( "" + "" + "" + "" + ""); private static System.Windows.Controls.ControlTemplate checkBoxTemplate = (System.Windows.Controls.ControlTemplate)System.Windows.Markup.XamlReader.Parse( "" + "" + "" + "" + ""); private System.Windows.Controls.TextBlock textBlock; protected new System.Windows.Controls.CheckBox control { get; } private Appearance appearance; public Appearance Appearance { get => appearance; set { if (value != appearance) { appearance = value; control.Template = value == Appearance.Button ? toggleButtonTemplate : checkBoxTemplate; control.ApplyTemplate(); } } } protected override void UpdateControlImage(ImageSource image) { if (Appearance == Appearance.Button) { var img = control.Template.FindName("image", control) as System.Windows.Controls.Image; img.Source = image; img.Visibility = image != null ? Visibility.Visible : Visibility.Collapsed; } } protected override void OnEnabledChanged(EventArgs e) { base.OnEnabledChanged(e); textBlock.Opacity = Enabled ? 1 : 0.5; } public CheckBox() { control = new(); SetControl(control); textBlock = new(); textBlock.TextWrapping = TextWrapping.Wrap; control.Content = textBlock; } } }