ButtonEditorControl.cs 1.7 KB

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