View Model Helper Class
As per .NET and Xamarin Forms guidelines, ViewModels usually implement the INotifyPropertyChanged
interface to inform the view of changes to the data model. This involves a lot of boilerplate, so VertiGIS Studio Mobile has a class, NotifyPropertyBase
, which handles the boilerplate and simplifies your code.
The ViewModel of the progress bar custom component is a good example of this pattern.
using App1.Components;
using VertiGIS.Mobile.Composition;
using VertiGIS.Mobile.Composition.Views;
[assembly: ViewModel(typeof(ProgressBarComponentViewModel))]
namespace App1.Components
{
public class ProgressBarComponentViewModel : NotifyPropertyBase
{
private double _progress = 0;
private bool _workComplete = false;
public double Progress
{
get => _progress;
set => SetProperty(ref _progress, value);
}
public bool WorkComplete
{
get => _workComplete;
set
{
SetProperty(ref _workComplete, value);
OnPropertyChanged(nameof(WorkNotComplete));
}
}
public bool WorkNotComplete => !WorkComplete;
}
}
NotifyPropertyBase
implements INotifyPropertyChanged
for you and provides a helper function, SetProperty
. This helper function will ensure that OnPropertyChanged
is called if the value has changed and that the underlying field is set.
Relevant SDK Sample
The VertiGIS Studio Mobile SDK Samples has an example of a breadcrumbs component that uses a viewmodel.