dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.04k stars 1.17k forks source link

A problem when Korean letter is typed into a TextBox control loaded inside a PopUp control #9360

Open SreemonPremkumarMuthukrishnan opened 2 months ago

SreemonPremkumarMuthukrishnan commented 2 months ago

Description

When I type a Korean letter inside the TextBox control, which is loaded inside the PopUp control, the first typed letter is not updated in the TextBox. When I type the second letter, both the first and the second letters are updated. This behavior continues with further typing.

Please find the code snippet below:

<Grid>
    <Button x:Name="PopupOpenButton" Content="Click to Open Popup" HorizontalAlignment="Left" Click="PopupOpenButton_Click"
        Margin="576,87,0,0" VerticalAlignment="Top" Height="37" Width="130"/>
    <Popup x:Name="myPopup" Width="500" Height="400" Placement="Mouse" AllowsTransparency="True">
        <Border Width="500" Height="400" Background="LightGray" BorderBrush="Black" BorderThickness="1">
            <TextBox  x:Name="SearchTextbox" Text="Search" HorizontalAlignment="Center" Height="30" 
                      TextWrapping="Wrap" VerticalAlignment="Center" Width="480"/>
        </Border>
    </Popup>
</Grid>

Please find the sample to replicate the issue:

KoreanIEM_SimpleSample.zip

Please find the video reference below:

https://github.com/dotnet/wpf/assets/104507189/2e1561a1-b455-49cb-abcc-35df7a59643a

Reproduction Steps

  1. Run the sample.
  2. Click the "Click to Open Popup" button.
  3. Type a Korean letter inside the Textbox
  4. Then type another Korean letter.

Expected behavior

The Korean letter should be able to update simultaneously when typing.

Actual behavior

The Korean letter shouldn't to update simultaneously when typing.

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

.NET version -> .NET framework 4.8.1 OS version -> Windows 11 Enterprise & Version - 22H2

Other information

No response

lindexi commented 2 months ago

@SreemonPremkumarMuthukrishnan Could you try my code:

[DllImport("User32.dll")]
public static extern IntPtr SetFocus(IntPtr hWnd);

IntPtr GetHwnd(Popup popup)
{
    HwndSource source = (HwndSource)PresentationSource.FromVisual(popup.Child);
    return source.Handle;
}

private void ShowPopupButtonClick(object sender, RoutedEventArgs e)
{
    ThePopup.IsOpen = true;
    IntPtr handle = GetHwnd(ThePopup);
    SetFocus(handle);
}

Or

[DllImport("USER32.DLL")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);

public static void ActivatePopup(Popup popup)
{
    HwndSource source = (HwndSource)PresentationSource.FromVisual(popup.Child);
    IntPtr handle = source.Handle;

    SetForegroundWindow(handle);
}

You can find my code demo in : https://github.com/lindexi/lindexi_gd/tree/1666e742fbd5ebda36e840a8e5f4b866251b3004/GakelfojeNairwogewerwhiheecem