-
Notifications
You must be signed in to change notification settings - Fork 697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Window.Activate does not activate and bring window to foreground in WinUI3 if window is in background but not minimized #7595
Comments
I ran into this issue when making my WinUI3 app single-instanced. Any idea when the bug could be resolved? |
Exactly where the bug hit me too. Had to call SetForegroundWindow. Please fix this. |
looking at it |
I just tried in the latest version of windows app sdk 1.2 and not able to reproduce it. I created a bunch of windows, stacked them one behind the other, called Can you verify that after updating to winappsdk 1.2, it goes away ? Feel free to re-open this bug if it still persists. |
This is not fixed in 1.2! Running code like this // Wire up the activated event handler.
keyInstance.Activated += async (sender, e) =>
{
// When activated, activate the main window and bring it to the foreground.
await _mainWindow.DispatcherQueue.EnqueueAsync(() => _mainWindow.Activate());
//NativeMethods.SetForegroundWindow(_mainWindow.GetWindowHandle());
}; outside the debugger, does not bring the window to the foreground. Only once the native call is uncommented the window is brought to the foreground! |
thanks for verifying it. i will try this out quickly. |
@Balkoth It looks like you are using Window community toolkit for dispatcher queue. Could you share a sample project which I can compile and build locally to investigate the issue? Meanwhile, I also have a workaround : if you move away from windows community toolkit and directly use dispatcher queue which is part of windows app sdk 1.2 It solves this issue. However, we definitely need to fix community toolkit bug so we need the repro too :) |
Is there a sample available for the Windows App SDK dispatcher queue? The link you posted puts a big question mark over my head... |
WinUI Gallery source code has some parts which uses this inbuilt dispatcher queue : https://github.com/microsoft/WinUI-Gallery/blob/353c1a0dab0aec9485179ad2a8b76cab95b7c8b9/WinUIGallery/TabViewPages/TabViewWindowingSamplePage.xaml.cs#L179 See if it helps. |
I will try it tomorrow and report back. |
Using the Windows App SDK dispatcher queue does also not work... // Wire up the activated event handler.
keyInstance.Activated += async (sender, e) =>
{
var taskCompletionSource = new TaskCompletionSource();
_mainWindow.DispatcherQueue.TryEnqueue(
Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal,
new Microsoft.UI.Dispatching.DispatcherQueueHandler(() =>
{
_mainWindow.Activate();
taskCompletionSource.SetResult();
}));
await taskCompletionSource.Task;
}; |
Here is the sample project: WindowActivateTest.zip |
thanks for confirming. i will try out this test app. |
Still investigating? |
Question: Why/when use this methiod over Show() ? |
This worked for me (I needed my app to be single instanced too and if user tried to run app again, already running instance's window get activated) This worked for me
in app.Xaml.cs
|
This is still an issue in Windows App SDK 1.3.2 (1.3.230602002) |
Seems to still be a problem in WASDK 1.4, is there any ETA for this? |
Does the explorer team using WinUi3 also just work around bugs like this? I would get really mad if i was on that team and long-standing bugs like this are still open. |
Worked like a champ, thank you. |
I was hitting the same issue today as well. My goal is to activate/foreground the apps single-instanced window after the user clicks a toast notification of the same app (a pretty common scenario I would say). The A similar behavior can be observed when using |
An API which generally works is SwitchToThisWindow |
@castorix sadly, this also doesn't work for me... |
I converted an old C++ function into C#, mixing all APIs.
with :
|
I did this as a temporary solution. In App.xaml.cs
In MainWindow:
common class in the project
|
hi Team, is there any update on this issue? Thanks. |
Will this issue anytime soon be fixed? |
It still exists in Windows App SDK 1.5.1 (1.5.240311000).
Using the Win32 API:
Using NuGet My English is not good.Hope it helps you. |
Thanks. It is in the list of bugs we have for fixing. Looking into it. Will update once I have something |
Some update : i have found the root issue and the fix. Now remains is the internal discussion over the fix. This is due to the fact Window.Activate() internally calls SetActiveWindow since its inception (source) . , WinUI could start calling SetForegroundWindow too but it would be a breaking change. We are currently assessing the impact on backward compatibility and then we will do the fix. |
How about creating a new method that calls SetForegroundWindow(), like Window.BringToForeground() to avoid the breaking change in Window.Activate() |
Any progress here? =) |
Is there any plan to address this? We're nearing six months since a fix was identified for this and there doesn't seem to have been any movement since then. Could we at least get the documentation updated with a remark describing the problem and linking back here so others don't lose time trying to figure out why windows aren't coming to the foreground when activated? |
Describe the bug
If
Activate
is called on aWindow
which is in the background of other windows, that window is not activated and brought to the foreground. If the window is minimized it works correctly.Steps to reproduce the bug
Call
Activate
on aWindow
when it is in the backround of other windows.Expected behavior
No response
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.1.4
Windows app type
Device form factor
Desktop
Windows version
Windows 10 (21H2): Build 19044
Additional context
No response
The text was updated successfully, but these errors were encountered: