Last active
August 1, 2023 21:50
-
-
Save worldbeater/1e70656f3aee4cc97bc00e21a583b1dc to your computer and use it in GitHub Desktop.
Traditional MVVM implementation. See: https://medium.com/@worldbeater/reactive-mvvm-for-net-platform-175dc69cfc82
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ViewModel : INotifyPropertyChanged | |
{ | |
public ViewModel() | |
{ | |
Clear = new Command(() => Name = string.Empty); | |
} | |
public ICommand Clear { get; } | |
public string Greeting => $"Hello, {Name}!"; | |
private string name = string.Empty; | |
public string Name | |
{ | |
get => name; | |
set | |
{ | |
if (name == value) return; | |
name = value; | |
OnPropertyChanged(nameof(Name)); // Raise the event for "Name" | |
OnPropertyChanged(nameof(Greeting)); // Raise the event for "Greeting" | |
} | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
protected virtual void OnPropertyChanged(string propertyName = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment