MemoEditorControl.cs 1.8 KB

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