BoolSetting.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Controls.Primitives;
  4. using System.Windows.Data;
  5. using System.Windows.Media;
  6. namespace PixiEditor.Models.Tools.ToolSettings.Settings
  7. {
  8. public class BoolSetting : Setting<bool>
  9. {
  10. public BoolSetting(string name, string label = "")
  11. : this(name, false, label)
  12. {
  13. }
  14. public BoolSetting(string name, bool isChecked, string label = "")
  15. : base(name)
  16. {
  17. Label = label;
  18. Value = isChecked;
  19. SettingControl = GenerateCheckBox();
  20. }
  21. private Control GenerateCheckBox()
  22. {
  23. CheckBox checkBox = new CheckBox
  24. {
  25. IsChecked = Value,
  26. VerticalAlignment = VerticalAlignment.Center
  27. };
  28. Binding binding = new Binding("Value")
  29. {
  30. Mode = BindingMode.TwoWay
  31. };
  32. checkBox.SetBinding(ToggleButton.IsCheckedProperty, binding);
  33. return checkBox;
  34. }
  35. }
  36. }