DigitalFormsHeader.xaml.cs 3.1 KB

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