RichTextEditorControl.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using InABox.Core;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. namespace InABox.DynamicGrid
  5. {
  6. public class RichTextEditorControl : DynamicEditorControl<string>
  7. {
  8. private RichTextEditor Editor;
  9. public override int DesiredHeight()
  10. {
  11. return int.MaxValue;
  12. }
  13. public override int DesiredWidth()
  14. {
  15. return int.MaxValue;
  16. }
  17. public override void SetColor(Color color)
  18. {
  19. Editor.SetColor(IsEnabled ? color : Colors.WhiteSmoke);
  20. }
  21. public override void SetEnabled(bool enabled)
  22. {
  23. Editor.Editor.IsReadOnly = !enabled;
  24. Editor.HideToolbar = !enabled;
  25. Editor.ZoomFactor = 100;
  26. SetColor(enabled ? Color : Colors.WhiteSmoke);
  27. }
  28. public override void SetFocus()
  29. {
  30. Editor.Focus();
  31. }
  32. protected override FrameworkElement CreateEditor()
  33. {
  34. using var profiler = new Profiler(true);
  35. MinHeight = 250;
  36. Editor = new RichTextEditor
  37. {
  38. VerticalAlignment = VerticalAlignment.Stretch,
  39. //VerticalContentAlignment = VerticalAlignment.Top,
  40. HorizontalAlignment = HorizontalAlignment.Stretch
  41. //VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
  42. //TextWrapping = TextWrapping.Wrap,
  43. //AcceptsReturn = true,
  44. };
  45. Editor.OnChanged += o => { CheckChanged(); };
  46. return Editor;
  47. }
  48. protected override string RetrieveValue()
  49. {
  50. return Editor.Text;
  51. }
  52. protected override void UpdateValue(string value)
  53. {
  54. Editor.Text = value;
  55. }
  56. }
  57. }