RichTextEditorControl.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.ZoomFactor = 100;
  29. SetColor(enabled ? Color : Colors.WhiteSmoke);
  30. }
  31. public override void SetFocus()
  32. {
  33. Editor.Focus();
  34. }
  35. public override void Configure()
  36. {
  37. }
  38. protected override FrameworkElement CreateEditor()
  39. {
  40. using var profiler = new Profiler(true);
  41. MinHeight = 250;
  42. Editor = new RichTextEditor
  43. {
  44. VerticalAlignment = VerticalAlignment.Stretch,
  45. //VerticalContentAlignment = VerticalAlignment.Top,
  46. HorizontalAlignment = HorizontalAlignment.Stretch,
  47. //VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
  48. //TextWrapping = TextWrapping.Wrap,
  49. //AcceptsReturn = true,
  50. VisibleButtons = EditorDefinition?.VisibleButtons ?? RichTextEditorButtons.All
  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. }