MemoEditorControl.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. CheckChanged();
  40. };
  41. Editor.LostFocus += (o, e) =>
  42. {
  43. if (IsChanged)
  44. CheckChanged();
  45. };
  46. return Editor;
  47. }
  48. public override int DesiredHeight()
  49. {
  50. return int.MaxValue;
  51. }
  52. public override int DesiredWidth()
  53. {
  54. return int.MaxValue;
  55. }
  56. protected override string RetrieveValue()
  57. {
  58. return Editor.Text;
  59. }
  60. protected override void UpdateValue(string value)
  61. {
  62. if (value != Editor.Text)
  63. Editor.Text = value;
  64. }
  65. public override void SetFocus()
  66. {
  67. Editor.Focus();
  68. Editor.CaretIndex = string.IsNullOrEmpty(Value) ? 0 : Value.Length;
  69. }
  70. public override void SetColor(Color color)
  71. {
  72. Editor.Background = new SolidColorBrush(color);
  73. }
  74. }
  75. }