ButtonEditorControl.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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, ButtonEditor>
  11. {
  12. static ButtonEditorControl()
  13. {
  14. //DynamicEditorControlFactory.Register<ButtonEditorControl, ButtonEditor>();
  15. }
  16. private Button Editor;
  17. private string _data = "";
  18. public Action<object, ButtonEditorClickArgs> OnClick { get; set; }
  19. protected override FrameworkElement CreateEditor()
  20. {
  21. Editor = new Button
  22. {
  23. Content = EditorDefinition.Label,
  24. HorizontalAlignment = HorizontalAlignment.Stretch,
  25. VerticalAlignment = VerticalAlignment.Stretch,
  26. VerticalContentAlignment = VerticalAlignment.Center,
  27. };
  28. Editor.Click += Editor_Click;
  29. return Editor;
  30. }
  31. public override void Configure()
  32. {
  33. if (EditorDefinition is not ButtonEditor editor) return;
  34. OnClick += editor.OnClick;
  35. }
  36. private void Editor_Click(object sender, RoutedEventArgs e)
  37. {
  38. var args = new ButtonEditorClickArgs() { Cancel = false, Data = _data };
  39. OnClick?.Invoke(this, args);
  40. if (!args.Cancel)
  41. _data = args.Data;
  42. }
  43. public override int DesiredHeight()
  44. {
  45. return 25;
  46. }
  47. public override int DesiredWidth()
  48. {
  49. return 100;
  50. }
  51. protected override string RetrieveValue()
  52. {
  53. return _data;
  54. }
  55. protected override void UpdateValue(string value)
  56. {
  57. _data = value;
  58. }
  59. public override void SetFocus()
  60. {
  61. Editor.Focus();
  62. }
  63. public override void SetColor(Color color)
  64. {
  65. }
  66. }
  67. }