BlobEditorControl.cs 1.7 KB

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