CustomBoolean.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 void SetFalseValue()
  56. {
  57. falseBtn.IsChecked = true;
  58. trueBtn.IsChecked = false;
  59. }
  60. public CustomBoolean(int rbGroup)
  61. {
  62. new ColumnDefinition { Width = new GridLength(70, GridUnitType.Absolute) };
  63. new ColumnDefinition { Width = new GridLength(70, GridUnitType.Absolute) };
  64. trueBtn.Content = "Yes";
  65. trueBtn.FontSize = Device.GetNamedSize(NamedSize.Small, trueBtn);
  66. trueBtn.TextColor = Color.Black;
  67. trueBtn.GroupName = rbGroup.ToString();
  68. trueBtn.HorizontalOptions = LayoutOptions.Center;
  69. trueBtn.VerticalOptions = LayoutOptions.Center;
  70. trueBtn.CheckedChanged += trueBtnSelected;
  71. Grid.SetColumn(trueBtn, 0);
  72. falseBtn.Content = "No";
  73. falseBtn.FontSize = Device.GetNamedSize(NamedSize.Small, trueBtn);
  74. falseBtn.TextColor = Color.Black;
  75. falseBtn.GroupName = rbGroup.ToString();
  76. falseBtn.HorizontalOptions = LayoutOptions.Center;
  77. falseBtn.VerticalOptions = LayoutOptions.Center;
  78. falseBtn.CheckedChanged += falseBtnSelected;
  79. Grid.SetColumn(falseBtn, 1);
  80. Children.Add(trueBtn);
  81. Children.Add(falseBtn);
  82. Padding = new Thickness(5);
  83. }
  84. private void trueBtnSelected(object sender, EventArgs e)
  85. {
  86. ValueChanged = true;
  87. OnCustomBooleanValueChanged?.Invoke(true);
  88. }
  89. private void falseBtnSelected(object sender, EventArgs e)
  90. {
  91. ValueChanged = true;
  92. OnCustomBooleanValueChanged?.Invoke(false);
  93. }
  94. }
  95. }