Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SelectableOption.cs
1using Microsoft.Maui.Controls;
2
4{
5 public class SelectableOption<T> : BindableObject, NeuroAccessMaui.Core.ISelectable
6 {
7 public T Item { get; }
8 private bool isSelectedBacking;
9 public bool IsSelected
10 {
11 get => this.isSelectedBacking;
12 set
13 {
14 if (this.isSelectedBacking != value)
15 {
16 this.isSelectedBacking = value;
17 this.OnPropertyChanged();
18 this.OnIsSelectedChanged();
19 }
20 }
21 }
22
23 private void OnIsSelectedChanged()
24 {
25 // Notify parent selector if available (for single selection enforcement)
26 this.IsSelectedChanged?.Invoke(this, EventArgs.Empty);
27 }
28
29 public event EventHandler? IsSelectedChanged;
30
31 public Command ToggleSelectionCommand { get; }
32 private readonly Action<SelectableOption<T>>? toggleAction;
33
34 public SelectableOption(T Item, bool IsSelected = false, Action<SelectableOption<T>>? ToggleAction = null)
35 {
36 this.Item = Item;
37 this.isSelectedBacking = IsSelected;
38 this.toggleAction = ToggleAction;
39 this.ToggleSelectionCommand = new Command(() => this.toggleAction?.Invoke(this));
40 }
41 }
42}