1using System.Reflection;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
4using CommunityToolkit.Mvvm.Messaging;
18 private readonly List<BaseViewModel> childViewModels = [];
19 private bool isOverlayVisible;
20 private DateTime overlayLastActivationTime;
42 public IEnumerable<BaseViewModel>
Children => this.childViewModels;
44 public virtual double ViewWidthRequest => (DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density) * (7.0 / 8.0);
45 public virtual double MaximumViewHeightRequest => (DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density) * (3.0 / 4.0);
64 this.childViewModels.Add(ChildViewModel);
65 return ChildViewModel;
76 this.childViewModels.Remove(ChildViewModel);
77 return ChildViewModel;
85 foreach (
BaseViewModel ChildViewModel
in this.childViewModels)
96 foreach (
BaseViewModel ChildViewModel
in this.childViewModels)
116 return Task.CompletedTask;
124 return Task.CompletedTask;
134 return this.GetType().FullName +
"." + PropertyName;
149 this.IsBusy = IsBusy;
157 get => this.isOverlayVisible;
160 if (this.isOverlayVisible == value)
165 this.isOverlayVisible =
true;
166 this.overlayLastActivationTime = DateTime.Now;
167 this.OnPropertyChanged();
171 TimeSpan MinimumOverlayTime = TimeSpan.FromMilliseconds(500);
172 TimeSpan ElapsedTime = DateTime.Now.Subtract(this.overlayLastActivationTime);
174 if (ElapsedTime >= MinimumOverlayTime)
176 this.isOverlayVisible =
false;
177 this.OnPropertyChanged();
183 Task.Delay(MinimumOverlayTime - ElapsedTime).GetAwaiter().OnCompleted(() => this.isOverlayVisible =
false);
197 this.IsInitialized =
true;
209 return Task.CompletedTask;
223 this.IsInitialized =
false;
235 return Task.CompletedTask;
248 DeviceDisplay.KeepScreenOn =
true;
252 foreach (
BaseViewModel ChildViewModel
in this.childViewModels)
255 this.IsAppearing =
true;
264 return Task.CompletedTask;
274 foreach (
BaseViewModel ChildViewModel
in this.childViewModels)
279 this.IsAppearing =
false;
288 return Task.CompletedTask;
318 public virtual object?
GetValue(
string PropertyName)
320 PropertyInfo? PI = this.GetType().GetProperty(PropertyName)
321 ??
throw new ArgumentException(
"Property not found: " + PropertyName, nameof(PropertyName));
323 return PI.GetValue(
this);
331 public virtual void SetValue(
string PropertyName,
object? Value)
333 PropertyInfo? PI = this.GetType().GetProperty(PropertyName)
334 ??
throw new ArgumentException(
"Property not found: " + PropertyName, nameof(PropertyName));
336 PI.SetValue(
this, Value);
Base class that references services in the app.
static IUiService UiService
Service serializing and managing UI-related tasks.
static ITagProfile TagProfile
TAG Profile service.
static IStringLocalizer Localizer
Localization service
A base class for all view models, inheriting from the BindableObject. NOTE: using this class requir...
static async Task< bool > AreYouSure(string Message)
Asks the user to confirm an action.
virtual Task OnDisappearing()
Method called when view is disappearing from the screen.
virtual Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
virtual Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
static void GoToRegistrationStep(RegistrationStep NewStep)
Set a new registration step
string GetSettingsKey(string PropertyName)
Helper method for getting a unique settings key for a given property.
virtual async Task DoAppearing()
Method called when view is appearing on the screen.
bool IsOverlayVisible
Gets or sets a value which indicates if the protective overlay with a spinner is visible.
virtual void SetValue(string PropertyName, object? Value)
Sets the value of a property in the view model.
T AddChildViewModel< T >(T ChildViewModel)
Use this method when nesting view models. This is the view model equivalent of master/detail pages.
T RemoveChildViewModel< T >(T ChildViewModel)
Use this method when nesting view models. This is the view model equivalent of master/detail pages.
virtual ? object GetValue(string PropertyName)
Gets the value of a property in the view model.
virtual Task DoRestoreState()
Override this method to do view model specific restoring of state when it's parent page/view appears ...
async Task Shutdown()
Convenience method that calls SaveState and then DoDisappearing.
bool IsAppearing
Returns true if the view model is shown.
virtual async Task GoBack()
Method called when user wants to navigate to the previous screen.
bool IsInitialized
Returns true if the view model is initialized.
IEnumerable< BaseViewModel > Children
Gets the child view models.
async Task DoDisappearing()
Method called when view is disappearing from the screen.
async Task DoDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
async Task DoInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
BaseViewModel()
Create an instance of a BaseViewModel.
async Task SaveState()
Called by the parent page when it disappears on screen, before the DoDisappearing method is called.
async Task RestoreState()
Called by the parent page when it appears on screen, after the DoAppearing method is called.
virtual Task DoSaveState()
Override this method to do view model specific saving of state when it's parent page/view disappears ...
virtual Task OnAppearing()
Method called when view is appearing on the screen.
virtual void SetIsBusy(bool IsBusy)
Sets the IsBusy property.
RegistrationStep Step
This profile's current registration step.
void GoToStep(RegistrationStep NewStep, bool SupressEvent=false)
Changes the current onboarding step.
Interface for views who need to react to life-cycle events.
RegistrationStep
The different steps of a TAG Profile registration journey.
class RegistrationPageMessage(RegistrationStep Step)
RegistrationPage view change message