views:

79

answers:

2

In the properties for the parent window I set WindowStatupLocation=CenterScreen In the properties for the Child window I set WindowStatupLocation=CenterOwner

on the button click in the parent window if i show child window, the child window position is not center owner.

Is this is a bug in WPF or I am doing something wrong?

+1  A: 

You have to set the owner of the child window to the parent window.

WindowChild windowChild = new WindowChild();
windowChild.WindowStartupLocation = WindowStartupLocation.CenterOwner; // you can set this in xaml
windowChild.Owner = this; // this is parent window
windowChild.Show();
Wallstreet Programmer
Thanks for the response. What if , If I showing the dialog from my viewmodel. I mean to say , How can I set the owner then ??
Ashish Ashu
A true VM should not be showing dialogs. Instead, add a bool property in the VM that the parent window will watch. When the VM sets it to true/false the parent window will show/hide the child window.
Wallstreet Programmer
A: 

Have you tried to explicitly set the ChildWindow.Parent property with the window that will be its parent ?

Serious