CustomBoolean.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using comal.timesheets.Tasks;
  8. using Comal.Classes;
  9. using InABox.Clients;
  10. using InABox.Configuration;
  11. using InABox.Core;
  12. using Xamarin.Forms;
  13. using Xamarin.Forms.Xaml;
  14. using XF.Material.Forms.UI;
  15. using XF.Material.Forms.UI.Dialogs;
  16. namespace comal.timesheets
  17. {
  18. public delegate void CustomBooleanValueChanged(bool value);
  19. class CustomBoolean : Grid
  20. {
  21. public event CustomBooleanValueChanged OnCustomBooleanValueChanged;
  22. public RadioButton trueBtn = new RadioButton();
  23. public RadioButton falseBtn = new RadioButton();
  24. private bool trueFalse;
  25. public bool ValueChanged { get; set; }
  26. public bool Value
  27. {
  28. get
  29. {
  30. if (trueBtn.IsChecked)
  31. {
  32. trueFalse = true;
  33. }
  34. else if (falseBtn.IsChecked)
  35. {
  36. trueFalse = false;
  37. }
  38. return trueFalse;
  39. }
  40. set
  41. {
  42. trueFalse = value;
  43. if (trueFalse)
  44. {
  45. trueBtn.IsChecked = true;
  46. falseBtn.IsChecked = false;
  47. }
  48. if (!trueFalse)
  49. {
  50. falseBtn.IsChecked = true;
  51. trueBtn.IsChecked = false;
  52. }
  53. }
  54. }
  55. public CustomBoolean(int rbGroup)
  56. {
  57. new ColumnDefinition { Width = new GridLength(70, GridUnitType.Absolute) };
  58. new ColumnDefinition { Width = new GridLength(70, GridUnitType.Absolute) };
  59. trueBtn.Content = "Yes";
  60. trueBtn.FontSize = Device.GetNamedSize(NamedSize.Small, trueBtn);
  61. trueBtn.TextColor = Color.Black;
  62. trueBtn.GroupName = rbGroup.ToString();
  63. trueBtn.HorizontalOptions = LayoutOptions.Center;
  64. trueBtn.VerticalOptions = LayoutOptions.Center;
  65. trueBtn.CheckedChanged += trueBtnSelected;
  66. Grid.SetColumn(trueBtn, 0);
  67. falseBtn.Content = "No";
  68. falseBtn.FontSize = Device.GetNamedSize(NamedSize.Small, trueBtn);
  69. falseBtn.TextColor = Color.Black;
  70. falseBtn.GroupName = rbGroup.ToString();
  71. falseBtn.HorizontalOptions = LayoutOptions.Center;
  72. falseBtn.VerticalOptions = LayoutOptions.Center;
  73. falseBtn.CheckedChanged += falseBtnSelected;
  74. Grid.SetColumn(falseBtn, 1);
  75. Children.Add(trueBtn);
  76. Children.Add(falseBtn);
  77. Padding = new Thickness(5);
  78. }
  79. private void trueBtnSelected(object sender, EventArgs e)
  80. {
  81. ValueChanged = true;
  82. OnCustomBooleanValueChanged?.Invoke(true);
  83. }
  84. private void falseBtnSelected(object sender, EventArgs e)
  85. {
  86. ValueChanged = true;
  87. OnCustomBooleanValueChanged?.Invoke(false);
  88. }
  89. }
  90. }