Skip to content
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

Fix issue that IME gets misplaced when text input control is on a Popup #3292

Merged
merged 2 commits into from
Aug 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions MaterialDesignThemes.Wpf/DialogHost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Runtime.InteropServices;
using System.Security;
using System.Windows.Data;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;

Expand Down Expand Up @@ -284,6 +287,7 @@ public DialogHost()
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
PreviewGotKeyboardFocus += OnPreviewGotKeyboardFocus;

CommandBindings.Add(new CommandBinding(CloseDialogCommand, CloseDialogHandler, CloseDialogCanExecute));
CommandBindings.Add(new CommandBinding(OpenDialogCommand, OpenDialogHandler));
Expand Down Expand Up @@ -947,4 +951,17 @@ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
}
}
}

private void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
if (_popup != null &&
PresentationSource.FromVisual(_popup.Child) is HwndSource hwndSource)
{
SetFocus(hwndSource.Handle);
}
}

[SecurityCritical]
[DllImport("user32.dll", EntryPoint = "SetFocus", SetLastError = true)]
private static extern IntPtr SetFocus(IntPtr hWnd);
}