Uebungsaufgaben/Semester3/DotNET/Aufgabenblatt6/Aufgabe17/Framework/ViewModelBase.cs

24 lines
788 B
C#
Raw Permalink Normal View History

2024-12-19 22:55:07 +00:00
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Aufgabe17.Framework
{
public abstract class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
}
}