ButtonEditorControl.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.ComponentModel;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using InABox.Core;
  7. using Syncfusion.XlsIO.Parser.Biff_Records.Charts;
  8. namespace InABox.DynamicGrid
  9. {
  10. public class ButtonEditorControl : DynamicEditorControl<string>
  11. {
  12. private Button Editor;
  13. private string _data = "";
  14. public string? Label { get; set; }
  15. public Action<object,ButtonEditorClickArgs> OnClick { get; set; }
  16. protected override FrameworkElement CreateEditor()
  17. {
  18. Editor = new Button
  19. {
  20. Content = Label,
  21. HorizontalAlignment = HorizontalAlignment.Stretch,
  22. VerticalAlignment = VerticalAlignment.Stretch,
  23. VerticalContentAlignment = VerticalAlignment.Center,
  24. };
  25. Editor.Click += Editor_Click;
  26. return Editor;
  27. }
  28. private void Editor_Click(object sender, RoutedEventArgs e)
  29. {
  30. var args = new ButtonEditorClickArgs() { Cancel = false, Data = _data };
  31. OnClick?.Invoke(this, args);
  32. if (!args.Cancel)
  33. _data = args.Data;
  34. }
  35. public override int DesiredHeight()
  36. {
  37. return 25;
  38. }
  39. public override int DesiredWidth()
  40. {
  41. return 100;
  42. }
  43. protected override string RetrieveValue()
  44. {
  45. return _data;
  46. }
  47. protected override void UpdateValue(string value)
  48. {
  49. _data = value;
  50. }
  51. public override void SetFocus()
  52. {
  53. Editor.Focus();
  54. }
  55. public override void SetColor(Color color)
  56. {
  57. }
  58. }
  59. }