Skip to content

Instantly share code, notes, and snippets.

@worldbeater
Last active August 1, 2023 21:50
Show Gist options
  • Save worldbeater/1e70656f3aee4cc97bc00e21a583b1dc to your computer and use it in GitHub Desktop.
Save worldbeater/1e70656f3aee4cc97bc00e21a583b1dc to your computer and use it in GitHub Desktop.
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