Skip to content

πŸ”— 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));
    }
}
Clone this wiki locally