-
-
Notifications
You must be signed in to change notification settings - Fork 4
π Observable Objects
mrousavy edited this page Aug 21, 2018
·
3 revisions
Every object with properties that need to be observed for changes needs to implement the ObservableObject
class:
public class User : ObservableObject
{
...
}
For view models see: View Models or Observable Objects π.
Using the Set
function allows for quick notifying properties:
private string _username;
public string Username
{
get => _username;
set => Set(ref _username, value);
}
If you are using ReSharper you can define a notify-property-changed-property template.
You can also force a PropertyChanged
invocation by using the Notify
function:
public string UserString => $"{Title} {Username}";
public string Username
{
get => _username;
set
{
Set(ref _username, value);
Notify(nameof(UserString));
}
}