DigitalFormLabel.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using InABox.Core;
  2. using Xamarin.Forms;
  3. namespace PRS.Mobile
  4. {
  5. public class DigitalFormLabel : Label, IDigitalFormControl<DFLayoutLabel>
  6. {
  7. private DFLayoutLabel _definition;
  8. public DFLayoutLabel Definition
  9. {
  10. get => _definition;
  11. set
  12. {
  13. _definition = value;
  14. Initialize(value ?? new DFLayoutLabel());
  15. }
  16. }
  17. public DigitalFormLabel()
  18. {
  19. MinimumHeightRequest = 60;
  20. VerticalOptions = LayoutOptions.FillAndExpand;
  21. HorizontalOptions = LayoutOptions.FillAndExpand;
  22. }
  23. private void Initialize(DFLayoutLabel label)
  24. {
  25. Text = label.Caption;
  26. LineBreakMode = label.Style.TextWrapping ? LineBreakMode.WordWrap : LineBreakMode.NoWrap;
  27. BackgroundColor = label.Style.BackgroundColour.IsEmpty ? Color.Transparent : label.Style.BackgroundColour;
  28. FontAttributes = label.Style.IsBold ? FontAttributes.Bold
  29. : label.Style.IsItalic ? FontAttributes.Italic
  30. : FontAttributes.None;
  31. TextDecorations = label.Style.Underline == UnderlineType.Single || label.Style.Underline == UnderlineType.Double ?
  32. TextDecorations.Underline : TextDecorations.None;
  33. FontSize = label.Style.FontSize > 5 && label.Style.FontSize < 37 ? label.Style.FontSize
  34. : Device.GetNamedSize(NamedSize.Small, this);
  35. TextColor = label.Style.ForegroundColour.IsEmpty ? Color.Black : label.Style.ForegroundColour;
  36. HorizontalTextAlignment = label.Style.HorizontalTextAlignment == DFLayoutAlignment.Start ? TextAlignment.Start
  37. : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle ? TextAlignment.Center
  38. : label.Style.HorizontalTextAlignment == DFLayoutAlignment.End ? TextAlignment.End
  39. : HorizontalTextAlignment;
  40. VerticalTextAlignment = label.Style.VerticalTextAlignment == DFLayoutAlignment.Start ? TextAlignment.Start
  41. : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle ? TextAlignment.Center
  42. : label.Style.HorizontalTextAlignment == DFLayoutAlignment.End ? TextAlignment.End
  43. : TextAlignment.Center;
  44. }
  45. }
  46. }