Here is WPF application consisting from 3 UserControl
s:
UserControl3
is a part of UserControl2
content. I keep MVVM during developing and using Prism.
I need to invoke custom class method (which is model in terms of MVVM) in UserControl3
from view-model of UserControl1
. The restriction that service in UserControl3
can't be singleton. I suppose to do it one of the following way:
Using event aggregator from Prism.
UserControl1
view-model is publisher andUserControl3
model is subscriber. For this I'll need to create unique Id inWindow
and pass it toUserControl1
andUserControl3
.Creating service instance in
Window
and pass it toUserControl1
andUserControl3
. ThenUserControl1
just invoke method on this instance.Window
passUserControl2
instance toUserControl1
. View-model inUserControl1
will just invoke method ofUserControl2
, which will invoke method ofUserControl3
and so on.
It seems like 2 and 3 approaches violates MVVM. What will you prefer?
I need to invoke custom class method (which is model in terms of MVVM) in UserControl3 from view-model of UserControl1
-- Why?