How should I focus an AppWindow? #1746
-
How should I let AppWindow get the focus and elevate to the top from other windows? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
If you want to focus it, yourAppWindow.Show(); //or yourAppWindow.Show(true); Unfocus with yourAppWindow.Show(false); Want to always stay on top? If it's a normal window (OverlappedPresenter): var presenter = yourAppWindow.Presenter as OverlappedPresenter;
presenter.IsAlwaysOnTop = true; |
Beta Was this translation helpful? Give feedback.
-
Hi @JohnCido, the AppWindow APIs don't support bringing the window to the foreground (I assume you are trying to bring your window to the foreground/front as a result of an app launch redirection or some other event that should bring your window to the foreground). The Here's how to bring a window to the foreground from a C# desktop app... 1. Install Microsoft.Windows.CsWin32 NuGet package2. Add NativeMethods.txt fileThis file specifies what C++ Win32 APIs you want projected into C#. We only need two APIs, so the file contents should simply be...
3. Bring your window to the foreground // Bring the window to the foreground... first get the window handle...
IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(m_window);
// Restore window if minimized... requires Microsoft.Windows.CsWin32 NuGet package and a NativeMethods.txt file with ShowWindow method
Windows.Win32.PInvoke.ShowWindow((Windows.Win32.Foundation.HWND)windowHandle, Windows.Win32.UI.WindowsAndMessaging.SHOW_WINDOW_CMD.SW_RESTORE);
// And call SetForegroundWindow... requires Microsoft.Windows.CsWin32 NuGet package and a NativeMethods.txt file with SetForegroundWindow method
Windows.Win32.PInvoke.SetForegroundWindow((Windows.Win32.Foundation.HWND)windowHandle); |
Beta Was this translation helpful? Give feedback.
Hi @JohnCido, the AppWindow APIs don't support bringing the window to the foreground (I assume you are trying to bring your window to the foreground/front as a result of an app launch redirection or some other event that should bring your window to the foreground). The
Show()
API unfortunately doesn't do that.Here's how to bring a window to the foreground from a C# desktop app...
1. Install Microsoft.Windows.CsWin32 NuGet package
2. Add NativeMethods.txt file
This file specifies what C++ Win32 APIs you want projected into C#. We only need two APIs, so the file contents should simply be...
3. Bring your window to the foreground
// Bring the window to th…