CustomBoolean.cs 3.2 KB

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