Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostSharp NotifyPropertyChanged Model - PropertyChangedEventHandler

Tags:

wpf

postsharp

I have litle problem with PostSharp Implementation of INotifyPropertyChanged. PostSharp added PropertyChangedEventHandler PropertyChanged after compile time, but I need react from C# too.

Model a = new Model();
a.PropertyChanged += a_PropertyChanged;

Model implementation;

[NotifyPropertyChanged]
internal class Model
{
    public string A { get; set; }

    public string B { get; set; }

    public string C { get { return string.Format("{0} - {1}", A, B); } }
}

I tried different ways to add handler,but unsuccessfully. Is there some way to do this?

like image 280
Peter Avatar asked Jun 23 '26 19:06

Peter


1 Answers

Instance of class decorated by NotifyPropertyChanged can be casted to INotifyPropertyChanged at runtime:

((INotifyPropertyChanged)a).PropertyChanged

There is a helper method Post.Cast to avoid "Suspicious cast" warning:

Post.Cast<Model, INotifyPropertyChanged>(a).PropertyChanged += OnPropertyChanged;
like image 86
Jakub Linhart Avatar answered Jun 28 '26 12:06

Jakub Linhart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!