From a0b311f5b9687f7e15b88d4ab3cb384eee96fcb3 Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 11 Aug 2023 10:48:50 +0900 Subject: [PATCH 1/2] Fix issue that IME gets misplaced when text input control is on a Popup Fixes #3147. --- MaterialDesignThemes.Wpf/DialogHost.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/MaterialDesignThemes.Wpf/DialogHost.cs b/MaterialDesignThemes.Wpf/DialogHost.cs index 96781897d6..96b851d3d9 100644 --- a/MaterialDesignThemes.Wpf/DialogHost.cs +++ b/MaterialDesignThemes.Wpf/DialogHost.cs @@ -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; @@ -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)); @@ -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); } From ec1c2e36fba132786c1fdacab1d04d2880807f44 Mon Sep 17 00:00:00 2001 From: Kevin Bost Date: Sun, 13 Aug 2023 15:17:47 -0700 Subject: [PATCH 2/2] Fixing UI tests with new XAMLTest version --- Directory.packages.props | 2 +- .../WPF/ListBoxes/ListBoxTests.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Directory.packages.props b/Directory.packages.props index 534acceb54..d728bea60d 100644 --- a/Directory.packages.props +++ b/Directory.packages.props @@ -22,7 +22,7 @@ - + diff --git a/MaterialDesignThemes.UITests/WPF/ListBoxes/ListBoxTests.cs b/MaterialDesignThemes.UITests/WPF/ListBoxes/ListBoxTests.cs index 313795dd96..501324cc8b 100644 --- a/MaterialDesignThemes.UITests/WPF/ListBoxes/ListBoxTests.cs +++ b/MaterialDesignThemes.UITests/WPF/ListBoxes/ListBoxTests.cs @@ -105,17 +105,17 @@ public async Task ScrollBarAssist_ButtonsVisibility_HidesButtonsOnMinimalistStyl var verticalScrollBar = await listBox.GetElement("PART_VerticalScrollBar"); var horizontalScrollBar = await listBox.GetElement("PART_HorizontalScrollBar"); - Assert.Equal(17, await verticalScrollBar.GetActualWidth()); + Assert.Equal(17.0, await verticalScrollBar.GetActualWidth(), 1.0); var verticalThumb = await verticalScrollBar.GetElement("/Thumb~border"); - Assert.Equal(10, await verticalThumb.GetActualWidth()); + Assert.Equal(10.0, await verticalThumb.GetActualWidth(), 1.0); var upButton = await verticalScrollBar.GetElement("PART_LineUpButton"); Assert.False(await upButton.GetIsVisible()); var downButton = await verticalScrollBar.GetElement("PART_LineDownButton"); Assert.False(await downButton.GetIsVisible()); - Assert.Equal(17, await horizontalScrollBar.GetActualHeight()); + Assert.Equal(17.0, await horizontalScrollBar.GetActualHeight(), 1.0); var horizontalThumb = await horizontalScrollBar.GetElement("/Thumb~border"); - Assert.Equal(10, await horizontalThumb.GetActualHeight()); + Assert.Equal(10.0, await horizontalThumb.GetActualHeight(), 1.0); var leftButton = await horizontalScrollBar.GetElement("PART_LineLeftButton"); Assert.False(await leftButton.GetIsVisible()); var rightButton = await horizontalScrollBar.GetElement("PART_LineRightButton");