Skip to content

Commit 8bbfa49

Browse files
Fix issue that IME gets misplaced when text input control is on a Popup (#3292)
Fixes #3147.
1 parent b89bbdf commit 8bbfa49

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Directory.packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageVersion Include="ShowMeTheXAML.AvalonEdit" Version="2.0.0" />
2323
<PackageVersion Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
2424
<PackageVersion Include="VirtualizingWrapPanel" Version="1.5.7" />
25-
<PackageVersion Include="XAMLTest" Version="1.0.0-ci417" />
25+
<PackageVersion Include="XAMLTest" Version="1.0.0-ci451" />
2626
<PackageVersion Include="xunit" Version="2.5.0" />
2727
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.0" />
2828
<PackageVersion Include="Xunit.StaFact" Version="1.1.11" />

MaterialDesignThemes.UITests/WPF/ListBoxes/ListBoxTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ public async Task ScrollBarAssist_ButtonsVisibility_HidesButtonsOnMinimalistStyl
105105
var verticalScrollBar = await listBox.GetElement<ScrollBar>("PART_VerticalScrollBar");
106106
var horizontalScrollBar = await listBox.GetElement<ScrollBar>("PART_HorizontalScrollBar");
107107

108-
Assert.Equal(17, await verticalScrollBar.GetActualWidth());
108+
Assert.Equal(17.0, await verticalScrollBar.GetActualWidth(), 1.0);
109109
var verticalThumb = await verticalScrollBar.GetElement<Border>("/Thumb~border");
110-
Assert.Equal(10, await verticalThumb.GetActualWidth());
110+
Assert.Equal(10.0, await verticalThumb.GetActualWidth(), 1.0);
111111
var upButton = await verticalScrollBar.GetElement<RepeatButton>("PART_LineUpButton");
112112
Assert.False(await upButton.GetIsVisible());
113113
var downButton = await verticalScrollBar.GetElement<RepeatButton>("PART_LineDownButton");
114114
Assert.False(await downButton.GetIsVisible());
115115

116-
Assert.Equal(17, await horizontalScrollBar.GetActualHeight());
116+
Assert.Equal(17.0, await horizontalScrollBar.GetActualHeight(), 1.0);
117117
var horizontalThumb = await horizontalScrollBar.GetElement<Border>("/Thumb~border");
118-
Assert.Equal(10, await horizontalThumb.GetActualHeight());
118+
Assert.Equal(10.0, await horizontalThumb.GetActualHeight(), 1.0);
119119
var leftButton = await horizontalScrollBar.GetElement<RepeatButton>("PART_LineLeftButton");
120120
Assert.False(await leftButton.GetIsVisible());
121121
var rightButton = await horizontalScrollBar.GetElement<RepeatButton>("PART_LineRightButton");

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
using System.Runtime.InteropServices;
2+
using System.Security;
13
using System.Windows.Data;
4+
using System.Windows.Interop;
25
using System.Windows.Media;
36
using System.Windows.Threading;
47

@@ -284,6 +287,7 @@ public DialogHost()
284287
{
285288
Loaded += OnLoaded;
286289
Unloaded += OnUnloaded;
290+
PreviewGotKeyboardFocus += OnPreviewGotKeyboardFocus;
287291

288292
CommandBindings.Add(new CommandBinding(CloseDialogCommand, CloseDialogHandler, CloseDialogCanExecute));
289293
CommandBindings.Add(new CommandBinding(OpenDialogCommand, OpenDialogHandler));
@@ -947,4 +951,17 @@ private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
947951
}
948952
}
949953
}
954+
955+
private void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
956+
{
957+
if (_popup != null &&
958+
PresentationSource.FromVisual(_popup.Child) is HwndSource hwndSource)
959+
{
960+
SetFocus(hwndSource.Handle);
961+
}
962+
}
963+
964+
[SecurityCritical]
965+
[DllImport("user32.dll", EntryPoint = "SetFocus", SetLastError = true)]
966+
private static extern IntPtr SetFocus(IntPtr hWnd);
950967
}

0 commit comments

Comments
 (0)