MemoEditorControl.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Media;
  4. using InABox.Core;
  5. namespace InABox.DynamicGrid
  6. {
  7. public class MemoEditorControl : DynamicEditorControl<string, MemoEditor>
  8. {
  9. static MemoEditorControl()
  10. {
  11. //DynamicEditorControlFactory.Register<MemoEditorControl, MemoEditor>();
  12. }
  13. private TextBox Editor;
  14. private bool IsChanged;
  15. public override void Configure()
  16. {
  17. }
  18. protected override FrameworkElement CreateEditor()
  19. {
  20. if (!EditorDefinition.Height.IsEffectivelyEqual(0.00))
  21. {
  22. MinHeight = EditorDefinition.Height;
  23. MaxHeight = EditorDefinition.Height;
  24. }
  25. else
  26. MinHeight = 50;
  27. Editor = new TextBox
  28. {
  29. VerticalAlignment = VerticalAlignment.Stretch,
  30. VerticalContentAlignment = VerticalAlignment.Top,
  31. HorizontalAlignment = HorizontalAlignment.Stretch,
  32. VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
  33. TextWrapping = TextWrapping.Wrap,
  34. AcceptsReturn = true,
  35. };
  36. Editor.TextChanged += (o, e) =>
  37. {
  38. IsChanged = true;
  39. if (EditorDefinition.ImmediateUpdates)
  40. CheckChanged();
  41. };
  42. Editor.LostFocus += (o, e) =>
  43. {
  44. if (IsChanged)
  45. CheckChanged();
  46. };
  47. return Editor;
  48. }
  49. public override int DesiredHeight()
  50. {
  51. return int.MaxValue;
  52. }
  53. public override int DesiredWidth()
  54. {
  55. return int.MaxValue;
  56. }
  57. protected override string RetrieveValue()
  58. {
  59. return Editor.Text;
  60. }
  61. protected override void UpdateValue(string value)
  62. {
  63. if (value != Editor.Text)
  64. Editor.Text = value;
  65. }
  66. public override void SetFocus()
  67. {
  68. Editor.Focus();
  69. Editor.CaretIndex = string.IsNullOrEmpty(Value) ? 0 : Value.Length;
  70. }
  71. public override void SetColor(Color color)
  72. {
  73. Editor.Background = new SolidColorBrush(color);
  74. }
  75. }
  76. }