Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 632e83b

Browse files
committed
Use SwitchToThisWindow native method to re-activate window
Window.Activate() doesn't seem to work when main window isn't visible.
1 parent 636b376 commit 632e83b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/GitHub.VisualStudio.UI/Views/Dialog/LoginCredentialsView.xaml.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.ComponentModel.Composition;
3+
using System.Diagnostics;
34
using System.Reactive.Disposables;
45
using System.Reactive.Linq;
6+
using System.Runtime.InteropServices;
57
using System.Windows;
68
using System.Windows.Input;
79
using GitHub.Controls;
@@ -46,7 +48,7 @@ public LoginCredentialsView()
4648
this.WhenAnyObservable(
4749
x => x.ViewModel.GitHubLogin.LoginViaOAuth,
4850
x => x.ViewModel.EnterpriseLogin.LoginViaOAuth)
49-
.Subscribe(_ => Application.Current.MainWindow?.Activate());
51+
.Subscribe(_ => SwitchToThisWindow());
5052

5153
hostTabControl.SelectionChanged += (s, e) =>
5254
{
@@ -122,5 +124,20 @@ void SetupSelectedTabBindings(Action<IDisposable> d)
122124
.Where(x => x == true)
123125
.BindTo(this, v => v.enterpriseTab.IsSelected));
124126
}
127+
128+
static void SwitchToThisWindow()
129+
{
130+
var hWnd = Process.GetCurrentProcess().MainWindowHandle;
131+
if (hWnd != IntPtr.Zero)
132+
{
133+
NativeMethods.SwitchToThisWindow(hWnd, true);
134+
}
135+
}
136+
137+
class NativeMethods
138+
{
139+
[DllImport("user32.dll")]
140+
internal static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
141+
}
125142
}
126143
}

0 commit comments

Comments
 (0)