简体   繁体   中英

MVVM and multiple windows

I'm in the pre-design stages of a small application that I'd like to write using Caliburn.Micro and C# / WPF. I'm still learning the framework, but I like what I see so far.

The application I intend to build is a process memory search/scan utility, with ASM disassembly and memory browsing capability. These three concerns - search/scan, ASM disassembly, and memory browsing - I'd like to be handled by three or more separate windows. The search/scan portion will comprise the main application shell, while the other two functions (which can be invoked multiple times simultaneously) will use separate windows invoked from actions on the shell.

My question is this: how do I launch new windows from within the shell (or some other) view model? I know I have to pass in another sort of view model for rendering in a new window - but it's that new window business that's confusing me.

Caliburn.Micro provides a WindowManager type with a Show method which can display a view model in a new window, and if that view model implements the appropriate Caliburn.Micro interfaces, the WindowManager will ensure the view model goes through the usual life cycle (ie it calls OnActivate , OnDeactivate etc). If your view models derive from the Screen type, then this will be the case.

WindowManager implements the IWindowManager interface, so you can inject this abstraction as a dependency into your ShellViewModel.

If the associated view is not a Window , but a UserControl , then the WindowManager will also wrap the UserControl in a Window so that it can be displayed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM