DigitalFormsHeader.xaml.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Xamarin.Forms;
  8. using Xamarin.Forms.Xaml;
  9. using static Android.Content.ClipData;
  10. namespace comal.timesheets
  11. {
  12. public delegate void DigitalFormsHeaderTapped(bool Collapsed);
  13. [XamlCompilation(XamlCompilationOptions.Compile)]
  14. public partial class DigitalFormsHeader : ContentView
  15. {
  16. public event DigitalFormsHeaderTapped OnTapped;
  17. public bool bCollapsed { get; set; }
  18. public int Number { get; set; }
  19. public DigitalFormsHeader (bool collapsed = false)
  20. {
  21. InitializeComponent ();
  22. bCollapsed = collapsed;
  23. Number = 0;
  24. }
  25. public void SetHeaderValue(string value)
  26. {
  27. headerBtn.Text = value;
  28. }
  29. private void HeaderBtn_Tapped(object sender, EventArgs e)
  30. {
  31. OnTapped?.Invoke(bCollapsed);
  32. AdjustHeaderArrow();
  33. }
  34. private void AdjustHeaderArrow()
  35. {
  36. if (bCollapsed)
  37. {
  38. bCollapsed = false;
  39. Expand();
  40. }
  41. else
  42. {
  43. bCollapsed = true;
  44. Collapse();
  45. }
  46. }
  47. private void Expand()
  48. {
  49. collapseColumn.Width = 40;
  50. collapseImage.IsVisible = true;
  51. expandColumn.Width = 0;
  52. expandImage.IsVisible = false;
  53. }
  54. public void Collapse()
  55. {
  56. collapseColumn.Width = 0;
  57. collapseImage.IsVisible = false;
  58. expandColumn.Width = 40;
  59. expandImage.IsVisible = true;
  60. }
  61. public void SetHeaderStyle(DFLayoutHeader label)
  62. {
  63. headerBtn.FontAttributes = label.Style.IsBold ? FontAttributes.Bold
  64. : label.Style.IsItalic ? FontAttributes.Italic
  65. : FontAttributes.None;
  66. headerBtn.FontSize = label.Style.FontSize > 5 && label.Style.FontSize < 37 ? label.Style.FontSize
  67. : Device.GetNamedSize(NamedSize.Medium, headerBtn);
  68. headerBtn.TextColor = label.Style.ForegroundColour;
  69. headerBtn.BackgroundColor = label.Style.BackgroundColour;
  70. headerBtn.HorizontalOptions = label.Style.HorizontalTextAlignment == DFLayoutAlignment.Start ? LayoutOptions.Start
  71. : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Middle ? LayoutOptions.Center
  72. : label.Style.HorizontalTextAlignment == DFLayoutAlignment.End ? LayoutOptions.End
  73. : label.Style.HorizontalTextAlignment == DFLayoutAlignment.Stretch ? LayoutOptions.FillAndExpand
  74. : LayoutOptions.StartAndExpand;
  75. headerBtn.VerticalOptions = label.Style.VerticalTextAlignment == DFLayoutAlignment.Start ? LayoutOptions.Start
  76. : label.Style.VerticalTextAlignment == DFLayoutAlignment.Middle ? LayoutOptions.Center
  77. : label.Style.VerticalTextAlignment == DFLayoutAlignment.End ? LayoutOptions.End
  78. : label.Style.VerticalTextAlignment == DFLayoutAlignment.Stretch ? LayoutOptions.FillAndExpand
  79. : LayoutOptions.Center;
  80. }
  81. }
  82. }