DFHeaderControl.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using InABox.Core;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. namespace InABox.DynamicGrid;
  10. public class DFHeaderControl : DynamicFormControl<DFLayoutHeader>
  11. {
  12. public FormHeader Header = null!;
  13. protected override FrameworkElement Create()
  14. {
  15. var style = Control.Style;
  16. Header = new FormHeader
  17. {
  18. Collapsed = Control.Collapsed,
  19. HeaderText = Control.Header,
  20. FontWeight = style.IsBold ? FontWeights.Bold : FontWeights.Normal,
  21. FontStyle = style.IsItalic ? FontStyles.Italic : FontStyles.Normal,
  22. };
  23. Header.CollapsedChanged += (o, c) =>
  24. {
  25. FormDesignGrid.CollapseRows(Header, c);
  26. };
  27. if (FormDesignGrid.IsDesigning)
  28. {
  29. Header.IsEnabled = false;
  30. }
  31. if (style.FontSize > 0)
  32. {
  33. Header.FontSize = style.FontSize;
  34. }
  35. if (style.BackgroundColour != System.Drawing.Color.Empty)
  36. {
  37. Header.Background = new SolidColorBrush(ConvertColour(style.BackgroundColour));
  38. }
  39. if (style.ForegroundColour != System.Drawing.Color.Empty)
  40. {
  41. Header.Foreground = new SolidColorBrush(ConvertColour(style.ForegroundColour));
  42. }
  43. if (style.Underline == UnderlineType.Single)
  44. {
  45. Header.TextDecorations.Add(TextDecorations.Underline);
  46. }
  47. else if (style.Underline == UnderlineType.Double)
  48. {
  49. var underline1 = new TextDecoration
  50. {
  51. Pen = new Pen
  52. {
  53. Brush = Header.Foreground,
  54. }
  55. };
  56. var underline2 = new TextDecoration
  57. {
  58. Pen = new Pen
  59. {
  60. Brush = Header.Foreground,
  61. },
  62. PenOffset = 2
  63. };
  64. Header.TextDecorations.Add(underline1);
  65. Header.TextDecorations.Add(underline2);
  66. }
  67. return Header;
  68. }
  69. private static Color ConvertColour(System.Drawing.Color colour)
  70. {
  71. return new Color { R = colour.R, G = colour.G, B = colour.B, A = colour.A };
  72. }
  73. }