CurrencyEditorControl.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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>
  11. {
  12. private CurrencyTextBox Editor;
  13. public CurrencyEditorControl()
  14. {
  15. Width = 150;
  16. }
  17. protected override FrameworkElement CreateEditor()
  18. {
  19. var DockPanel = new DockPanel
  20. {
  21. //Orientation = Orientation.Horizontal,
  22. HorizontalAlignment = HorizontalAlignment.Stretch
  23. };
  24. var buttons = CreateButtons(out var bDisableEditor);
  25. foreach(var button in buttons)
  26. {
  27. button.SetValue(DockPanel.DockProperty, Dock.Right);
  28. button.Click += (o, e) =>
  29. {
  30. var b = (Button)o;
  31. var eb = b.Tag as EditorButton;
  32. eb.Click(this);
  33. };
  34. DockPanel.Children.Add(button);
  35. }
  36. Editor = new CurrencyTextBox
  37. {
  38. HorizontalAlignment = HorizontalAlignment.Stretch,
  39. VerticalAlignment = VerticalAlignment.Stretch,
  40. VerticalContentAlignment = VerticalAlignment.Center,
  41. HorizontalContentAlignment = HorizontalAlignment.Center,
  42. CurrencyDecimalDigits = (EditorDefinition as CurrencyEditor).Digits
  43. };
  44. Editor.ValueChanged += (o, e) => { CheckChanged(); };
  45. Editor.SetValue(DockPanel.DockProperty, Dock.Left);
  46. if (bDisableEditor)
  47. {
  48. Editor.Background = new SolidColorBrush(Colors.Silver);
  49. Editor.IsEnabled = false;
  50. }
  51. DockPanel.Children.Add(Editor);
  52. return DockPanel;
  53. }
  54. public override int DesiredHeight()
  55. {
  56. return 25;
  57. }
  58. public override int DesiredWidth()
  59. {
  60. var result = 150;
  61. var btnEditor = EditorDefinition as IButtonEditor;
  62. if (btnEditor?.Buttons != null)
  63. foreach (var button in ((IButtonEditor)EditorDefinition).Buttons)
  64. result += button.Width + 5;
  65. return result;
  66. }
  67. protected override double RetrieveValue()
  68. {
  69. return Convert.ToDouble(Editor.Value);
  70. }
  71. protected override void UpdateValue(double value)
  72. {
  73. Editor.Value = Convert.ToDecimal(value);
  74. }
  75. public override void SetFocus()
  76. {
  77. Editor.Focus();
  78. }
  79. public override void SetColor(Color color)
  80. {
  81. Editor.Background = new SolidColorBrush(color);
  82. }
  83. }
  84. }