[NotifyPropertyChanged] aspect ignores [Parent] property

dnogin's Avatar

dnogin

17 Sep, 2018 04:23 AM

[NotifyPropertyChanged] aspect ignores [Parent] property, so no events are raised when parent property is changed. It prevents me from setting up an observable subscription to monitor outside properties in my child constructor using Gu.Reactive or something like that. An example:

[Aggregatable]
[NotifyPropertyChanged]
[ContentProperty("Pages")]
public class Wizard : INotifyPropertyChanged
{
    [Child, AggregateAllChanges] public AdvisableCollection<Page> Pages { get; } = new AdvisableCollection<Page>();

    public event PropertyChangedEventHandler PropertyChanged = delegate { };
    void OnPropertyChanged(string propertyName) => 
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}

[Aggregatable]
[NotifyPropertyChanged]
public class Page : INotifyPropertyChanged
{
    public Page()
    {
        this.ObservePropertyChangedWithValue(p => p.Wizard.Pages)
            .ItemPropertyChanged<AdvisableCollection<Page>, Page, bool>(p => p.Valid)                
            .Subscribe(e => SignalPropertyChanged(this, nameof(Enabled)));
    }

    [Parent] public Wizard Wizard { get; private set; }
    public string Name { get; set; }
    public bool Valid { get; set; }

    [SafeForDependencyAnalysis] public bool Enabled => Wizard.Pages
        .TakeWhile(p => p != this)
        .All(p => p.Valid);

    public event PropertyChangedEventHandler PropertyChanged = delegate { };
    void OnPropertyChanged(string propertyName) => 
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}

There is no notification for Wizard property being set on Page, so property changes are not being observed.

  1. Support Staff 1 Posted by PostSharp Techn... on 19 Sep, 2018 08:14 PM

    PostSharp Technologies's Avatar

    Hello,

    Indeed, there is a compatibility issue between NotifyPropertyChanged and Aggregatable aspects that affects the parent property. We are investigating the issue and we'll update the related discussion on StackOverflow: https://stackoverflow.com/questions/52359967/tracking-property-chan...

    -alex

  2. PostSharp Technologies closed this discussion on 19 Sep, 2018 08:14 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac