MemoEditorControl.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. MinHeight = 50;
  21. Editor = new TextBox
  22. {
  23. VerticalAlignment = VerticalAlignment.Stretch,
  24. VerticalContentAlignment = VerticalAlignment.Top,
  25. HorizontalAlignment = HorizontalAlignment.Stretch,
  26. VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
  27. TextWrapping = TextWrapping.Wrap,
  28. AcceptsReturn = true
  29. };
  30. Editor.TextChanged += (o, e) =>
  31. {
  32. IsChanged = true;
  33. //CheckChanged();
  34. };
  35. Editor.LostFocus += (o, e) =>
  36. {
  37. if (IsChanged)
  38. CheckChanged();
  39. };
  40. return Editor;
  41. }
  42. public override int DesiredHeight()
  43. {
  44. return int.MaxValue;
  45. }
  46. public override int DesiredWidth()
  47. {
  48. return int.MaxValue;
  49. }
  50. protected override string RetrieveValue()
  51. {
  52. return Editor.Text;
  53. }
  54. protected override void UpdateValue(string value)
  55. {
  56. if (value != Editor.Text)
  57. Editor.Text = value;
  58. }
  59. public override void SetFocus()
  60. {
  61. Editor.Focus();
  62. Editor.CaretIndex = string.IsNullOrEmpty(Value) ? 0 : Value.Length;
  63. }
  64. public override void SetColor(Color color)
  65. {
  66. Editor.Background = new SolidColorBrush(color);
  67. }
  68. }
  69. }