XAML INotifyPropertyChanged Example

Date: 2021-01-08
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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));
}
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)); }
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
0 of 2000 max characters.