wpf icon indicating copy to clipboard operation
wpf copied to clipboard

In an Arabic (ar) environment, TextBlock Run behaves abnormally when displaying pure numbers.

Open daigs opened this issue 1 month ago • 6 comments

Description

In an Arabic (ar) environment, TextBlock Run behaves abnormally when displaying pure numbers.

Image Image

Reproduction Steps

Create a new .NET 9 WPF application and add the following code:

    public MainWindow()
    {
        CultureInfo.CurrentUICulture = new CultureInfo("ar");
        this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentUICulture.Name);
        this.FlowDirection = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;

        InitializeComponent();
    }

<Window
    x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <TextBlock FontSize="18" FontWeight="Bold">
            <Run d:Text="25.4.10.10" Text="99.99.99.99" />
            <LineBreak />
            <Run d:Text="801" Text="801" />
            <LineBreak />
            <Run d:Text="802" Text="802" />
            <LineBreak />
            <Run d:Text="803" Text="803" />
            <LineBreak />
        </TextBlock>
    </Grid>
</Window>

Expected behavior

Display numbers normally

Actual behavior

The displayed numbers are abnormal, like garbled text.

Image

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

daigs avatar Oct 16 '25 06:10 daigs

Please clarify what you mean by normally and abnormally. I assume you are referring to the three squares between 99.

I cannot reproduce this.

Image

What is your Windows build number?

miloush avatar Oct 16 '25 09:10 miloush

Also try if adding this to your project file helps:

  <ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
  </ItemGroup>

miloush avatar Oct 16 '25 10:10 miloush

Also try if adding this to your project file helps:

  <ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
  </ItemGroup>

Even after adding this configuration, it is still the same as before.

daigs avatar Oct 17 '25 00:10 daigs

Please clarify what you mean by normally and abnormally. I assume you are referring to the three squares between 99.

I cannot reproduce this.

Image What is your Windows build number?

Can you use the code I provided above to provide a screenshot of the running results?

daigs avatar Oct 17 '25 00:10 daigs

Image After I added the fixed attribute value Language="en", it displayed correctly. I added this attribute to all the Run controls in my project that display pure numbers to solve this problem.

daigs avatar Oct 17 '25 00:10 daigs

I used your code, but you did not clarify what you consider normal and abnormal. Are you reporting that you see Arabic digits when you set the UI culture to Arabic? That is expected.

miloush avatar Oct 17 '25 09:10 miloush