Get notified if property in childviewmodel is changed

Topics: Questions
Jun 4, 2014 at 8:36 AM
Hello.

Ist it possible to get notified in the viewmodel if a property in childviewmodel is changed?
Coordinator
Jun 4, 2014 at 9:08 AM
Not out of the box. You will have to implement that yourself (would be too costly for performance).
Jun 4, 2014 at 9:30 AM
Ok. The only chance I see is with the InterestedIn Attribute.

But this costs a lot of more performance because not only the parent is notified.

In "OnViewModelPropertyChanged()" I have to check if I'am the parent of sending child.

Do you have any other idea?
Coordinator
Jun 4, 2014 at 10:00 AM
See https://catelproject.atlassian.net/wiki/display/CTL/MVVM+communication+styles. Probably it is better to use a dedicated service for what you are trying to achieve with events. Then you are in full control.
Jun 4, 2014 at 10:13 AM
Sorry not realy clear what you mean. What do you wan't to show me in the link? The MessageMediator?
Coordinator
Jun 4, 2014 at 10:16 AM
Different ways of communicating with Catel, they should all be in there.
Jun 4, 2014 at 11:19 AM
Edited Jun 4, 2014 at 11:19 AM
Yes ok. Thats clear. But with MessageMediator I have the same problem as with InterestedIn.

Thats my Nested structure:

HouseViewModel A
  • RoomViewmodel A1
    • FurnitureViewModel A1X
    • FurnitureViewModel A1Y
    • FurnitureViewModel A1Z
  • RoomViewmodel A2
    • FurnitureViewModel A2X
  • RoomViewmodel A3
HouseViewModel B
  • RoomViewmodel B1
  • RoomViewmodel B2
  • RoomViewmodel B3
HouseViewModel C
  • RoomViewmodel C1
  • RoomViewmodel C2
  • RoomViewmodel C3
and so on...

If FurnitureViewModel A1X changes a property only RoomViewmodel A1 is Interested in. But if I use the IterstedIn Attribute or the MessageMediator
every Roomviewmodel in every HouseViewmodel is notified.
Jun 5, 2014 at 5:31 AM
What do you mean with:
Probably it is better to use a dedicated service for what you are trying to achieve with events. Then you are in full control.
Coordinator
Jun 5, 2014 at 8:34 AM
I don't know about your architecture, nor do I know if this communication is for VM's only. But normally I create a service to manage such subscriptions (for example, you subscribe to a specific tag / object notification). Then the service will handle this communication for you.