Two questions here.
My view has a "close" button that when clicked, the window should close. I handled this as follows: The button in my view binds to a command defined in the view's view model, which when triggered runs the following:
private void Exit()
{
var regionManager = Container.Resolve<IRegionManager>();
MyView existingView = regionManager.Regions["MyWindowRegion"].GetView("MyView") as MyView;
if (existingView != null)
{
regionManager.Regions["MyWindowRegion"].Remove(existingView);
}
}
Is this ok? Does the view model now know too much about the view (such as its name and type)?
Similar to the first question, in my module toolbar, if I hit a "launch module" button it will create/display a view. I made it so that if the view is already visible, instead of creating it again, the view model will just bring the existing one into focus:
private void LaunchMyView()
{
var regionManager = Container.Resolve<IRegionManager>();
MyView existingView = regionManager.Regions["MyWindowRegion"].GetView("MyView") as MyView;
if (existingView == null)
{
MyView view = Container.Resolve<MyView>();
view.Title = "MyView Title";
regionManager.Regions["MyWindowRegion"].Add(view, "MyView");
}
else
{
regionManager.Regions["MyWindowRegion"].Activate(existingView);
}
}
Same question. Does the view model know too much about the view?
Btw, I am using the WindowsRegionAdapter to handle new view creation.
Thanks.