Answered by:
Show WPF window insite another WPF window

Question
-
I have this code and it works fine.
public class WindowHelper { private const int GWL_STYLE = (-16); private const UInt32 WS_POPUP = 0x80000000; private const UInt32 WS_CHILD = 0x40000000; [DllImport("user32.dll", SetLastError = true)] private static extern UInt32 GetWindowLongApi(IntPtr hWnd, int nIndex); [DllImport("user32.dll")] private static extern int SetWindowLongApi(IntPtr hWnd, int nIndex, UInt32 dwNewLong); [DllImport("user32.dll", SetLastError = true)] private static extern IntPtr SetParentApi(IntPtr hWndChild, IntPtr hWndNewParent); public void SetParent(Window childWindow, Window parentWindow) { childWindow.Owner = parentWindow; childWindow.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner; childWindow.Show(); IntPtr childWindowHandle = new WindowInteropHelper(childWindow).Handle; IntPtr parentWindowHandle = new WindowInteropHelper(parentWindow).Handle; uint windowStyle = GetWindowLongApi(childWindowHandle, GWL_STYLE); windowStyle = (windowStyle & ~(WS_POPUP)) | WS_CHILD; SetWindowLongApi(childWindowHandle, GWL_STYLE, windowStyle); SetParentApi(childWindowHandle, parentWindowHandle); } }
But if I would like to have a modal ChildWindow this code doesn´t work. To pop up a modal window I use ".ShowDialog();". To use ".ShowDialog();" in my code I have to show up my ChildWindow first with ".Show();" than I take the current style from that and than I ".Hide();" the ChildWindow again. Now I can use ".ShowDialog();" to get a modal window. But this ChildWindow shows no reaction of any mouse or keyboard action from me.
Thank you,
Eric Weber
Wednesday, December 5, 2012 4:10 PM
Answers
-
Use this method to show your modal window:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/820bf10f-3eaf-43a8-b5ef-b83b2394342c
http://code.msdn.microsoft.com/windowsdesktop/Modeless-Window-in-WPF-492cb24f
Stay hungry, stay foolish
- Edited by Helper.WPF Friday, December 7, 2012 7:11 AM
- Marked as answer by Sheldon _Xiao Thursday, December 20, 2012 6:43 AM
Friday, December 7, 2012 6:58 AM
All replies
-
Use this method to show your modal window:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/820bf10f-3eaf-43a8-b5ef-b83b2394342c
http://code.msdn.microsoft.com/windowsdesktop/Modeless-Window-in-WPF-492cb24f
Stay hungry, stay foolish
- Edited by Helper.WPF Friday, December 7, 2012 7:11 AM
- Marked as answer by Sheldon _Xiao Thursday, December 20, 2012 6:43 AM
Friday, December 7, 2012 6:58 AM -
Hi Eric,
I am marking your issue as "Answered", if you have new findings about your issue, please let me know.
Best regards,Sheldon _Xiao
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Thursday, December 20, 2012 6:43 AM