RichTextEditorControl.cs 2.2 KB

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