XAML INotifyPropertyChanged Example

Date: 2021-01-08
public class XamlViewModel : INotifyPropertyChanged
{
	private bool selected;
	public bool Selected { get => selected; set { selected = value; OnPropertyChanged(); OnPropertyChanged(nameof(Background)); } }

	public Brush Background => selected ? new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)) : new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); 

	public event PropertyChangedEventHandler PropertyChanged;
	[NotifyPropertyChangedInvocator]
	protected virtual void OnPropertyChanged([CallerMemberName] string property = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
44250cookie-checkXAML INotifyPropertyChanged Example