My simplified program structure looks like this:
public class Manager
{
public Item MyItem { get; set; }
public void Recalculate(){ ... }
}
public class Item
{
public string SomeProperty { get; set; }
}
public class ManagerViewModel
{
public Manager Model { get; set; }
public ItemViewModel MyItem { get; set; }
}
public class ItemViewModel
{
public Item Model { get; set; }
public string SomeProperty
{
get => Model.SomeProperty;
set
{
Model.SomeProperty = value;
RaisePropertyChanged("SomeProperty");
}
}
}
When SomeProperty
gets changed in ItemViewModel
, I want Recalculate()
to get triggered inside Manager.
Do I:
A) Have a PropertyChangedListener inside ManagerViewModel
which listens for Property changes inside it's MyItem
, and then tells it's Model to Recalculate()
B) Allow ItemViewModel to have access to Manager, so it can manually tell Manager to run Recalculate()
..
(B) seems kind of anti-pattern-ish... shouldn't each ViewModel only really be concerned with it's own Model? (A) has it's own issues -- I need to use this sort of 'Recalculation' structure a lot, and it seems having these PropertyChangedListeners all over the place is kind of messy. I realise there's a few different ways of going about this, but I'm just wondering what the 'best practice' is in this case.