123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using InABox.Core;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace InABox.DynamicGrid
- {
- public class DFLabelControl : DynamicFormControl<DFLayoutLabel>
- {
- protected override FrameworkElement Create()
- {
- var border = new Border
- {
- HorizontalAlignment = HorizontalAlignment.Stretch,
- VerticalAlignment = VerticalAlignment.Stretch
- };
- var style = Control.Style;
- var textBlock = new TextBlock
- {
- Text = Control.Caption,
- TextWrapping = TextWrapping.WrapWithOverflow,
- FontWeight = style.IsBold ? FontWeights.Bold : FontWeights.Normal,
- FontStyle = style.IsItalic ? FontStyles.Italic : FontStyles.Normal,
- VerticalAlignment = Control.Style.VerticalTextAlignment switch
- {
- DFLayoutAlignment.Start => VerticalAlignment.Top,
- DFLayoutAlignment.End => VerticalAlignment.Bottom,
- DFLayoutAlignment.Stretch => VerticalAlignment.Stretch,
- _ => VerticalAlignment.Center
- },
- HorizontalAlignment = HorizontalAlignment.Stretch,
- TextAlignment = Control.Style.HorizontalTextAlignment switch
- {
- DFLayoutAlignment.Middle => TextAlignment.Center,
- DFLayoutAlignment.End => TextAlignment.Right,
- DFLayoutAlignment.Stretch => TextAlignment.Justify,
- _ => TextAlignment.Left
- },
- Margin = new Thickness(5)
- };
- if(style.FontSize > 0)
- {
- textBlock.FontSize = style.FontSize;
- }
- if (style.BackgroundColour != System.Drawing.Color.Empty)
- {
- border.Background = new SolidColorBrush(ConvertColour(style.BackgroundColour));
- }
- if (style.ForegroundColour != System.Drawing.Color.Empty)
- {
- textBlock.Foreground = new SolidColorBrush(ConvertColour(style.ForegroundColour));
- }
- if (style.Underline == UnderlineType.Single)
- {
- textBlock.TextDecorations.Add(TextDecorations.Underline);
- }
- else if(style.Underline == UnderlineType.Double)
- {
- var underline1 = new TextDecoration
- {
- Pen = new Pen
- {
- Brush = textBlock.Foreground,
- }
- };
- var underline2 = new TextDecoration
- {
- Pen = new Pen
- {
- Brush = textBlock.Foreground,
- },
- PenOffset = 2
- };
- textBlock.TextDecorations.Add(underline1);
- textBlock.TextDecorations.Add(underline2);
- }
- border.Child = textBlock;
- return border;
- }
- private static Color ConvertColour(System.Drawing.Color colour)
- {
- return new Color { R = colour.R, G = colour.G, B = colour.B, A = colour.A };
- }
- }
- }
|