-1

I'm currently working on a WPF app and I am facing a situation.

To make it simple, I have a mainwindow with multiple UserControl in it. At some point, I have another window opening, and I want this window to always being focused, even if the user try to click on the other one.

I found some things about the Window.Activate() method. So I tried this solution. But it doesn't work like I would. I need my window to be the only one accessible for the user, and I don't want him to access the main one when the second one is not closed.

Obviously, I really want not to break the MVVM.

Any clue ?

Quentin S.
  • 328
  • 2
  • 16

1 Answers1

0

If you want a single window to be the only one the user interacts with then use .ShowDialog rather than show. Any instantiation of manipulation of windows is a view responsibility so put the code that will do that in one of your usercontrol or windows. Then you need some way to make that happen from your viewmodel. You can add a dependency property to your view and bind that to a property in the viewmodel then handle the change of that dependency property. An alternative would be to use the pub/sub pattern and mvvmlight messenger or a bridging object like prism eventaggregator. Or any number of other bridging mechanisms you could share via resources or dependency injection.

Andy
  • 11,864
  • 2
  • 17
  • 20