2021-01-31 11:05:37 +01:00
|
|
|
# ViewModel.cs
|
|
|
|
|
|
|
|
```cs
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Text;
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
namespace AppName.ViewModels
|
|
|
|
{
|
|
|
|
class PageNameViewModel : INotifyPropertyChanged
|
|
|
|
{
|
|
|
|
public MainPageViewModel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged; // event handler to notify changes
|
|
|
|
|
|
|
|
public string field; // needed, if substituted by ExprBody will cause infinite loop of access with the binding
|
|
|
|
public string Property
|
|
|
|
{
|
|
|
|
get => field;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
field = value;
|
|
|
|
|
|
|
|
var args = new PropertyChangedEventArgs(nameof(Property)); // EVENT: let view know that the Property has changed
|
2021-09-20 19:35:32 +02:00
|
|
|
PropertyChanged?.Invoke(this, args); // Invoke event to notify the view
|
2021-01-31 11:05:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|