CurrencyEditorControl.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Linq;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using InABox.Core;
  7. using Syncfusion.Windows.Shared;
  8. namespace InABox.DynamicGrid
  9. {
  10. public class CurrencyEditorControl : DynamicEditorControl<double, CurrencyEditor>
  11. {
  12. static CurrencyEditorControl()
  13. {
  14. //DynamicEditorControlFactory.Register<CurrencyEditorControl, CurrencyEditor>();
  15. }
  16. private CurrencyTextBox Editor;
  17. public CurrencyEditorControl()
  18. {
  19. Width = 150;
  20. }
  21. public override void Configure()
  22. {
  23. }
  24. protected override FrameworkElement CreateEditor()
  25. {
  26. var DockPanel = new DockPanel
  27. {
  28. //Orientation = Orientation.Horizontal,
  29. HorizontalAlignment = HorizontalAlignment.Stretch
  30. };
  31. var buttons = CreateButtons(out var bDisableEditor);
  32. foreach(var button in buttons)
  33. {
  34. button.SetValue(DockPanel.DockProperty, Dock.Right);
  35. DockPanel.Children.Add(button);
  36. }
  37. Editor = new CurrencyTextBox
  38. {
  39. HorizontalAlignment = HorizontalAlignment.Stretch,
  40. VerticalAlignment = VerticalAlignment.Stretch,
  41. VerticalContentAlignment = VerticalAlignment.Center,
  42. HorizontalContentAlignment = HorizontalAlignment.Center,
  43. CurrencyDecimalDigits = (EditorDefinition as CurrencyEditor).Digits
  44. };
  45. Editor.ValueChanged += (o, e) => { CheckChanged(); };
  46. Editor.SetValue(DockPanel.DockProperty, Dock.Left);
  47. if (bDisableEditor)
  48. {
  49. Editor.Background = new SolidColorBrush(Colors.Silver);
  50. Editor.IsEnabled = false;
  51. }
  52. DockPanel.Children.Add(Editor);
  53. return DockPanel;
  54. }
  55. public override int DesiredHeight()
  56. {
  57. return 25;
  58. }
  59. public override int DesiredWidth()
  60. {
  61. var result = 150;
  62. var btnEditor = EditorDefinition as IButtonEditor;
  63. if (btnEditor?.Buttons != null)
  64. foreach (var button in ((IButtonEditor)EditorDefinition).Buttons)
  65. result += button.Width + 5;
  66. return result;
  67. }
  68. protected override double RetrieveValue()
  69. {
  70. return Convert.ToDouble(Editor.Value);
  71. }
  72. protected override void UpdateValue(double value)
  73. {
  74. Editor.Value = Convert.ToDecimal(value);
  75. }
  76. public override void SetFocus()
  77. {
  78. Editor.Focus();
  79. }
  80. public override void SetColor(Color color)
  81. {
  82. Editor.Background = new SolidColorBrush(color);
  83. }
  84. }
  85. }