Notify aspect support for MVVM UI and property changed snippets
$ dotnet add package OutWit.Common.AspectsA lightweight runtime AOP library for automating INotifyPropertyChanged notifications in.NET.
Implementing INotifyPropertyChanged is essential for data binding in modern.NET UI frameworks like WPF, MAUI, and Avalonia, but it often leads to verbose, repetitive, and error-prone boilerplate code in your ViewModels.
OutWit.Common.Aspects solves this problem by providing a simple, runtime-based "aspect" that automatically injects property change notifications into your classes.
Install-Package OutWit.Common.Aspects
or
> dotnet add package OutWit.Common.Aspects
public class MyViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged = delegate { };
private string m_text;
public MyViewModel()
{
this.PropertyChanged += OnPropertyChanged;
}
private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Text")
{
Trace.Write("I am here!");
}
}
public string Text
{
get => m_text;
set
{
m_text = value;
PropertyChanged(this, new PropertyChangedEventArgs("Text"));
}
}
}
public class MyViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged = delegate { };
public MyViewModel()
{
this.PropertyChanged += OnPropertyChanged;
}
private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.IsProperty((MyViewModel vm) => vm.Text))
{
Trace.Write("I am here!");
}
}
[Notify]
public string Text { get; set; }
}
For more details, check out the article.
Licensed under the Apache License, Version 2.0. See .
LICENSEIf you use OutWit.Common.Aspects in a product, a mention is appreciated (but not required), for example: "Powered by OutWit.Common.Aspects (https://ratner.io/)".
"OutWit" and the OutWit logo are used to identify the official project by Dmitry Ratner.
You may:
You may not: