MobileCheckBox.xaml.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Globalization;
  3. using Xamarin.Forms;
  4. using Xamarin.Forms.Xaml;
  5. namespace InABox.Mobile
  6. {
  7. public class CheckBoxImageConverter : IValueConverter
  8. {
  9. public ImageSource Checked { get; set; }
  10. public ImageSource Unchecked { get; set; }
  11. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  12. {
  13. if ((value is bool ischecked) && ischecked)
  14. return Checked;
  15. return Unchecked;
  16. }
  17. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  18. {
  19. throw new NotImplementedException();
  20. }
  21. }
  22. [XamlCompilation(XamlCompilationOptions.Compile)]
  23. public partial class MobileCheckBox
  24. {
  25. public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(
  26. nameof(IsChecked),
  27. typeof(bool),
  28. typeof(MobileCheckBox),
  29. false);
  30. public bool IsChecked
  31. {
  32. get => (bool)GetValue(IsCheckedProperty);
  33. set => SetValue(IsCheckedProperty,value);
  34. }
  35. public event EventHandler Changed;
  36. public MobileCheckBox()
  37. {
  38. InitializeComponent();
  39. }
  40. private void ToggleCheck(object sender, EventArgs e)
  41. {
  42. IsChecked = !IsChecked;
  43. Changed?.Invoke(this,EventArgs.Empty);
  44. }
  45. }
  46. }