简体   繁体   中英

How do I display a modal dialog using WPF and Prism?

We're doing a WPF application using Prism.

We're using the 'view-first' approach where our views are injected with the VM ( IFooViewModel ).

We want to hook up a UI action in a view to display a modal dialog box. We want to do this the 'proper' Prism way, ie just specifying a URI and not hard-coding a particular View or ViewModel .

There seems to be very few examples of achieving this seemingly trivial goal.

As I assume you are also using the DI containers from PRISM, you can try using Inversion of Control. Basicly what you do is the following.

Each view has it's own interface. In that interface you define your code with events and such. You then inject the Interface into the viewmodel without it ever knowing anything about the view. Except the necessary events of course

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