DoubleEditorControl.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, DoubleEditor>
  8. {
  9. static DoubleEditorControl()
  10. {
  11. //DynamicEditorControlFactory.Register<DoubleEditorControl, DoubleEditor>();
  12. }
  13. private DoubleTextBox Editor;
  14. public DoubleEditorControl()
  15. {
  16. Width = 150;
  17. }
  18. protected override FrameworkElement CreateEditor()
  19. {
  20. var def = EditorDefinition as DoubleEditor;
  21. var digits = def != null ? def.Digits : 2;
  22. Editor = new DoubleTextBox
  23. {
  24. VerticalAlignment = VerticalAlignment.Stretch,
  25. VerticalContentAlignment = VerticalAlignment.Center,
  26. HorizontalAlignment = HorizontalAlignment.Stretch,
  27. HorizontalContentAlignment = HorizontalAlignment.Center,
  28. NumberDecimalDigits = digits
  29. };
  30. Editor.ValueChanged += (o, e) => CheckChanged();
  31. return Editor;
  32. }
  33. public override void Configure()
  34. {
  35. Editor.NumberDecimalDigits = EditorDefinition.Digits;
  36. }
  37. public override int DesiredHeight()
  38. {
  39. return 25;
  40. }
  41. public override int DesiredWidth()
  42. {
  43. return 150;
  44. }
  45. protected override double RetrieveValue()
  46. {
  47. return Editor.Value.HasValue ? Editor.Value.Value : default;
  48. }
  49. protected override void UpdateValue(double value)
  50. {
  51. Editor.Value = value;
  52. }
  53. public override void SetFocus()
  54. {
  55. Editor.Focus();
  56. }
  57. public override void SetColor(Color color)
  58. {
  59. Editor.Background = new SolidColorBrush(color);
  60. }
  61. }
  62. }