using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using comal.timesheets.Tasks; using Comal.Classes; using InABox.Clients; using InABox.Configuration; using InABox.Core; using Xamarin.Forms; using Xamarin.Forms.Xaml; using XF.Material.Forms.UI; using XF.Material.Forms.UI.Dialogs; namespace comal.timesheets { public delegate void CustomBooleanValueChanged(bool value); class CustomBoolean : Grid { public event CustomBooleanValueChanged OnCustomBooleanValueChanged; public RadioButton trueBtn = new RadioButton(); public RadioButton falseBtn = new RadioButton(); private bool trueFalse; public bool ValueChanged { get; set; } public bool Value { get { if (trueBtn.IsChecked) { trueFalse = true; } else if (falseBtn.IsChecked) { trueFalse = false; } return trueFalse; } set { trueFalse = value; if (trueFalse) { trueBtn.IsChecked = true; falseBtn.IsChecked = false; } if (!trueFalse) { falseBtn.IsChecked = true; trueBtn.IsChecked = false; } } } public void SetFalseValue() { falseBtn.IsChecked = true; trueBtn.IsChecked = false; } public CustomBoolean(int rbGroup) { new ColumnDefinition { Width = new GridLength(70, GridUnitType.Absolute) }; new ColumnDefinition { Width = new GridLength(70, GridUnitType.Absolute) }; trueBtn.Content = "Yes"; trueBtn.FontSize = Device.GetNamedSize(NamedSize.Small, trueBtn); trueBtn.TextColor = Color.Black; trueBtn.GroupName = rbGroup.ToString(); trueBtn.HorizontalOptions = LayoutOptions.Center; trueBtn.VerticalOptions = LayoutOptions.Center; trueBtn.CheckedChanged += trueBtnSelected; Grid.SetColumn(trueBtn, 0); falseBtn.Content = "No"; falseBtn.FontSize = Device.GetNamedSize(NamedSize.Small, trueBtn); falseBtn.TextColor = Color.Black; falseBtn.GroupName = rbGroup.ToString(); falseBtn.HorizontalOptions = LayoutOptions.Center; falseBtn.VerticalOptions = LayoutOptions.Center; falseBtn.CheckedChanged += falseBtnSelected; Grid.SetColumn(falseBtn, 1); Children.Add(trueBtn); Children.Add(falseBtn); Padding = new Thickness(5); } private void trueBtnSelected(object sender, EventArgs e) { ValueChanged = true; OnCustomBooleanValueChanged?.Invoke(true); } private void falseBtnSelected(object sender, EventArgs e) { ValueChanged = true; OnCustomBooleanValueChanged?.Invoke(false); } } }