Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DurationPopupViewModel.cs
1using System.Collections.ObjectModel;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
6
8{
9 public partial class DurationPopupViewModel : ReturningPopupViewModel<DurationUnits?>
10 {
11 [ObservableProperty]
12 private ObservableCollection<TextButton> buttons;
13
14 public DurationPopupViewModel(ObservableCollection<DurationUnits> AvailableUnits)
15 {
16 this.Buttons = new ObservableCollection<TextButton>();
17
18 // Populate buttons based on the available units
19 foreach (DurationUnits Unit in AvailableUnits)
20 {
21 this.Buttons.Add(new TextButton
22 {
23 LabelData = ServiceRef.Localizer[Unit.ToString() + "Capitalized"],
24 Command = new AsyncRelayCommand(async () => await this.SelectUnitAsync(Unit))
25 });
26 }
27 }
28
29 // Close command to dismiss the popup
30 [RelayCommand]
31 private static async Task Close()
32 {
33 await ServiceRef.PopupService.PopAsync();
34 }
35
36 // Command that handles unit selection
37 private async Task SelectUnitAsync(DurationUnits unit)
38 {
39 this.TrySetResult(unit);
40 await ServiceRef.PopupService.PopAsync();
41 }
42
43 protected override Task OnPopAsync()
44 {
45 if (!this.Result.IsCompleted)
46 {
47 this.TrySetResult(null);
48 }
49 return base.OnPopAsync();
50 }
51 }
52}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IPopupService PopupService
Popup service for presenting application popups.
Definition: ServiceRef.cs:142
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
DurationUnits
Duration units enumeration