Determinar si la ventana activa es una ventana WPF
Frecuentes
Visto 904 veces
1 Respuestas
5
Utilice las HwndSource
.
http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndsource.fromhwnd.aspx
Como sigue:
IntPtr hwnd = GetActivewWindow();
HwndSource hwndsrc = HwndSource.FromHwnd(hwnd);
// Use any variation on this code
if (hwndsrc != null && hwndsrc.RootVisual != null)
{
Window window = hwndsrc.RootVisual as Window;
if (window != null)
{
window.Close();
}
// UPDATE: I've added looking for a "Popup" window as well
// because your question mentions "pop up window"...but
// not sure if you meant a top-level Window, or a Popup...
// ....Popup windows have HWND too!
Popup popupwindow = hwndsrc.RootVisual as Popup;
if (popupwindow != null)
{
popupwindow.IsOpen = false;
}
}
Respondido el 17 de junio de 13 a las 23:06
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# .net wpf winforms or haz tu propia pregunta.
How does the code ensures that it is a WPF window and the window does not correspond to a form? - maanu
It won't correspond to a Windows Form...as HwndSource will only return something if it's with a HWND which is connected to some WPF Visuals. In the example I showed checking whether that RootVisual was a WPF Window, as that was the thing you want to check for. - Csmith