CurrencyEditorControl.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. button.Click += (o, e) =>
  36. {
  37. var b = (Button)o;
  38. var eb = b.Tag as EditorButton;
  39. eb.Click(this);
  40. };
  41. DockPanel.Children.Add(button);
  42. }
  43. Editor = new CurrencyTextBox
  44. {
  45. HorizontalAlignment = HorizontalAlignment.Stretch,
  46. VerticalAlignment = VerticalAlignment.Stretch,
  47. VerticalContentAlignment = VerticalAlignment.Center,
  48. HorizontalContentAlignment = HorizontalAlignment.Center,
  49. CurrencyDecimalDigits = (EditorDefinition as CurrencyEditor).Digits
  50. };
  51. Editor.ValueChanged += (o, e) => { CheckChanged(); };
  52. Editor.SetValue(DockPanel.DockProperty, Dock.Left);
  53. if (bDisableEditor)
  54. {
  55. Editor.Background = new SolidColorBrush(Colors.Silver);
  56. Editor.IsEnabled = false;
  57. }
  58. DockPanel.Children.Add(Editor);
  59. return DockPanel;
  60. }
  61. public override int DesiredHeight()
  62. {
  63. return 25;
  64. }
  65. public override int DesiredWidth()
  66. {
  67. var result = 150;
  68. var btnEditor = EditorDefinition as IButtonEditor;
  69. if (btnEditor?.Buttons != null)
  70. foreach (var button in ((IButtonEditor)EditorDefinition).Buttons)
  71. result += button.Width + 5;
  72. return result;
  73. }
  74. protected override double RetrieveValue()
  75. {
  76. return Convert.ToDouble(Editor.Value);
  77. }
  78. protected override void UpdateValue(double value)
  79. {
  80. Editor.Value = Convert.ToDecimal(value);
  81. }
  82. public override void SetFocus()
  83. {
  84. Editor.Focus();
  85. }
  86. public override void SetColor(Color color)
  87. {
  88. Editor.Background = new SolidColorBrush(color);
  89. }
  90. }
  91. }