DoubleEditorControl.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Windows;
  2. using System.Windows.Media;
  3. using InABox.Core;
  4. using Syncfusion.Windows.Shared;
  5. namespace InABox.DynamicGrid
  6. {
  7. public class DoubleEditorControl : DynamicEditorControl<double>
  8. {
  9. private DoubleTextBox Editor;
  10. public DoubleEditorControl()
  11. {
  12. Width = 150;
  13. }
  14. protected override FrameworkElement CreateEditor()
  15. {
  16. var def = EditorDefinition as DoubleEditor;
  17. var digits = def != null ? def.Digits : 2;
  18. Editor = new DoubleTextBox
  19. {
  20. VerticalAlignment = VerticalAlignment.Stretch,
  21. VerticalContentAlignment = VerticalAlignment.Center,
  22. HorizontalAlignment = HorizontalAlignment.Stretch,
  23. HorizontalContentAlignment = HorizontalAlignment.Center,
  24. NumberDecimalDigits = digits
  25. };
  26. Editor.ValueChanged += (o, e) => CheckChanged();
  27. return Editor;
  28. }
  29. public override void Configure()
  30. {
  31. var def = EditorDefinition as DoubleEditor;
  32. if (def != null)
  33. Editor.NumberDecimalDigits = def.Digits;
  34. base.Configure();
  35. }
  36. public override int DesiredHeight()
  37. {
  38. return 25;
  39. }
  40. public override int DesiredWidth()
  41. {
  42. return 150;
  43. }
  44. protected override double RetrieveValue()
  45. {
  46. return Editor.Value.HasValue ? Editor.Value.Value : default;
  47. }
  48. protected override void UpdateValue(double value)
  49. {
  50. Editor.Value = value;
  51. }
  52. public override void SetFocus()
  53. {
  54. Editor.Focus();
  55. }
  56. public override void SetColor(Color color)
  57. {
  58. Editor.Background = new SolidColorBrush(color);
  59. }
  60. }
  61. }