123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- namespace InABox.Mobile
- {
-
- public class MobileRadioListChangedEventArgs : EventArgs
- {
- }
- public delegate void MobileRadioListChangedEvent(object sender, MobileRadioListChangedEventArgs args);
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class MobileRadioList
- {
-
- private readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(
- nameof(BackgroundColor),
- typeof(Color),
- typeof(MobileRadioList),
- XF.Material.Forms.Material.Color.Surface);
- [TypeConverter(typeof(ColorTypeConverter))]
- public Color BackgroundColor
- {
- get => (Color)GetValue(BackgroundColorProperty);
- set => SetValue(BackgroundColorProperty, value);
- }
-
- private readonly BindableProperty TextColorProperty = BindableProperty.Create(
- nameof(TextColor),
- typeof(Color),
- typeof(MobileRadioList),
- XF.Material.Forms.Material.Color.OnSurface);
- [TypeConverter(typeof(ColorTypeConverter))]
- public Color TextColor
- {
- get => (Color)GetValue(TextColorProperty);
- set => SetValue(TextColorProperty, value);
- }
-
- private readonly BindableProperty BorderColorProperty = BindableProperty.Create(
- nameof(BorderColor),
- typeof(Color),
- typeof(MobileRadioList),
- XF.Material.Forms.Material.Color.Secondary);
-
- public Color BorderColor
- {
- get => (Color)GetValue(BorderColorProperty);
- set => SetValue(BorderColorProperty, value);
- }
-
- public IList<MobileRadioListItem> Items { get; }
-
- public MobileRadioListItem SelectedItem
- {
- get => Items.FirstOrDefault(x => x.IsChecked);
- set
- {
- foreach (var item in Items)
- item.IsChecked = item == value;
- }
- }
- public event MobileRadioListChangedEvent Changed;
-
- public MobileRadioList()
- {
- Items = new ObservableCollection<MobileRadioListItem>();
- InitializeComponent();
- BindingContext = this;
- _list.ItemsSource = Items;
- BackgroundColor = XF.Material.Forms.Material.Color.Surface;
- }
-
- private void Tapped(object sender, EventArgs e)
- {
- if ((sender as BindableObject)?.BindingContext is MobileRadioListItem item)
- {
- if (item != SelectedItem)
- {
- SelectedItem = item;
- Changed?.Invoke(this, new MobileRadioListChangedEventArgs());
- _list.ItemsSource = null;
- _list.ItemsSource = Items;
- }
- }
- }
- }
- }
|