The relationship of the ViewModel with the ViewModel is usually handled by the implementation of the event aggregator pattern.
MVVM Light uses a class Messenger, Prism has a different implementation, but basically this is one way to send messages between View Models without communication.
There are several examples and Articles describing use. I would suggest looking at him.
As for the controller elements in WPF, I don't know.
Regarding the example:
- Windows WindowsViewModel. , Button.
- . .
- .
- . ViewModel, ViewModel , .
- , ,
, , :
bool? ShowDialogImpl<TViewModel>(Action<TViewModel> setup) where TViewModel : ViewModel
{
return (bool?)DispatcherHelper.UIDispatcher.Invoke(
(Func<bool?>)(() =>
{
var viewModel = viewModelFactory.Get<TViewModel>();
viewModel.ViewService = this;
setup(viewModel);
var window = new Window
{
Owner = this,
SizeToContent = SizeToContent.WidthAndHeight,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Content = ViewFactory.CreateView<TViewModel>(),
DataContext = viewModel,
WindowStyle = WindowStyle.ToolWindow,
ShowInTaskbar = false
};
window.SetBinding(TitleProperty, new Binding("Title"));
openDialogs.Push(window);
window.Activated += (sender, args) => window.SizeToContent = SizeToContent.Manual;
var result = window.ShowDialog();
openDialogs.Pop();
viewModelFactory.Release(viewModel);
return result;
}));
}
: .
factory .
.
Windows - Grid, Dialog - .
Inf the Windows :
messenger.Register<EntityUpdated<FooClass>>(this, message => UpdateItem(message.Entity));
:
messenger.Send(new EntityUpdated<FooClass>(subject));
, , - "", .
, :)