How to make edge browser show in front of my UWP app?

Xie Steven 831 Reputation points
2020-11-20T06:49:28.85+00:00

Hello,

This issue was related to UWP app and c# console application.

I made a simple server by using c# console application. And my UWP will run in full-screen mode and connect to it.

My console application will start a process to open the edge browser and do someting.

Process.Start("http://.....");

As the UWP app was running in full-screen mode, the edge browser did not open in front of my UWP app. It just shows in the task bar. For making the edge show on top, I have to move my mouse to the bottom of the screen and click the edge in task bar.

I have tried the win32 APIs.

[DllImport("user32.dll")]
public static extern int ShowWindow(IntPtr hWnd, uint nCmdShow);

public static extern bool SetForegroundWindow(IntPtr hWnd);

public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

It only worked on the desktop computer. If I run my UWP and console application on laptop, it did not work. Any idea will be appreciated.

Thanks,
Steven

Universal Windows Platform (UWP)
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
337 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
{count} votes

Accepted answer
  1. Amy Peng-MSFT 251 Reputation points Microsoft Employee
    2020-12-04T01:51:34.137+00:00

    Hi XieSteven,

    Based on this SetForegroundWindow API:

    “An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.”

    It should be not supported, but you said that this is working on Desktop, there might be some environmental variables that is affecting this behavior on your Desktop vs Laptop, however its recommended that the process that’s already on the foreground (the UWP application) should be the one that starts the new process (Edge) to avoid any issues down the line.

    Thanks.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.