views:

24

answers:

2

Hello, I'm writing in wpf. In my viewModel I have a command that opens new window. However sometimes this child window is placed under the parent window. (if for instance I work in my application, then open browser and want to return to my application). Window is opened as follows:

MyViewModel vm = new MyViewModel(oper);
Mywindow window = new MyWindow();
//Initialize viewModel and set window.DataContext to this viewModel
CWPFWindowWithViewModelHelper<IWindowWithViewModel>.InitializeViewModel(window, vm);
window.ShowDialog();

I want this child window to be always visible when opened. How can I do this?

A: 
window.TopMost = true;
Thomas Levesque
It will be applied for all windows in system and not just for parent.
niao
Certainly not "all windows in system"... it will be applied to the window on which you set the property, and perhaps on its child windows. Did you try it ?
Thomas Levesque
Ah, ok I see what you mean now. Do you want the window to be modal ? (i.e. disable the parent window until it's closed)
Thomas Levesque
what I mean, when I set window.TopMost=true to my child window, it will be always on top (e.g. even if I open other windows like browser etc). And yes I want it to be modal
niao
I want to set window.Owner=this but this is my ViewModel and it doesn't know anything about parent window.
niao
A: 

just try with

window.Owner=this
Kishore Kumar
but how can I do this in my ViewModel? Please remember that I am creating new child window in my ViewModel so "this" will reference to currentViewModel
niao
Since it is a ViewModel and not a Model, I would have assumed it had a reference to the parent View (i.e. Window).
Jonathan Allen