2

I use the awesome weaver PropertyChanged.Fody for avoiding INotifyPropertyChanged boilerplate. I define dependent properties like this:

public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName { get { return FirstName + " " + LastName; } }

However, this method does not work with subproperties. What I want to achieve is something like this:

public Person MyChild { get; set; }
public string ChildName { get { return MyChild.FullName } }

When MyChild.FirstName changes, I want ChildName to notify that it is also changed. Is is possible to achieve this without explicitly subscribing to MyChild.PropertyChanged and manually calling RaisePropertyChanged("ChildName")?

Geir Sagberg
  • 9,632
  • 8
  • 45
  • 60
  • As far as I can tell, this problem falls outside the realm of what PropertyChanged.Fody can solve. I've started looking at functional reactive programming via Reactive Extensions, seems promising so far. – Geir Sagberg Apr 29 '15 at 20:35
  • Bello I'm in the same situation... Have you got far on this? – advapi May 15 '15 at 03:45
  • @advapi I found the easiest way was to use some kind of subscription like MvvmCross' `WeakSubscribe()`: https://github.com/MvvmCross/MvvmCross/tree/3.5/CrossCore/Cirrious.CrossCore/WeakSubscription – Geir Sagberg May 19 '15 at 08:33
  • `PostSharp` can solve this case. see: https://doc.postsharp.net/inotifypropertychanged-dependencies – CodingNinja Feb 13 '22 at 04:14

0 Answers0