RichTextEditorControl.cs 2.0 KB

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