WPF is not support bid unicode?

305 views Asked by At

I have a WPF application.

I want to display Hebrew sentence that involved numbers and words.

I read about Unicode bidi and write little code for that as following:

 const string PDF = "\u202C"; 
 const string LRO = "\u202D"; 
 const string RLO = "\u202E"; 
 const string TEXT = "ערך ראשון : ערך שני";

 var parts = TEXT.Split(':');
 double number = -50;
 double number2 = -200;
 string str = string.Empty;

 str +=RLO + parts[0] + PDF;
 str +=LRO + number + PDF;
 str +=RLO + parts[1] + PDF;
 str +=LRO + shortValue + PDF;
 Text = str;

Now in xaml:

    <TextBlock Text="FlowDirection=LeftToRight TextAlignment=Right Language=he-IL" Grid.Column="0" Grid.Row="0" />
    <TextBlock Text="{Binding Text}" FlowDirection="LeftToRight" Language="he-IL" TextAlignment="Right" Grid.Column="1" Grid.Row="0"/>

    <TextBlock Text="FlowDirection=LeftToRight TextAlignment=Left Language=he-IL" Grid.Column="0" Grid.Row="1"/>
    <TextBlock Text="{Binding Text}" FlowDirection="LeftToRight"  Language="he-IL" TextAlignment="Left" Grid.Column="1" Grid.Row="1"/>

    <TextBlock Text="FlowDirection=RightToLeft TextAlignment=Left Language=he-IL" Grid.Column="0" Grid.Row="2"/>
    <TextBlock Text="{Binding Text}" FlowDirection="RightToLeft"  Language="he-IL" TextAlignment="Left" Grid.Column="1" Grid.Row="2"/>

    <TextBlock Text="FlowDirection=RightToLeft TextAlignment=Right Language=he-IL" Grid.Column="0" Grid.Row="3"/>
    <TextBlock Text="{Binding Text}" FlowDirection="RightToLeft"  Language="he-IL" TextAlignment="Right" Grid.Column="1" Grid.Row="3"/>

But it seems that it's not supported in WPF - as we can to see here:

enter image description here

The negative numbers doesn't designed proper..

Edit:

Thanks a lot to Hans Passant for his link.

I change the values of LRO and RLO to those:

    const string LRO = "\u200E";
    const string RLO = "\u200F"; 

And now it designed proper.

enter image description here

Thanks!

1

There are 1 answers

1
Peter On

You have to print numbers with the right culture. Right now you tell the program exactly how to write the string, and it does as you tell it to.

If you need some special number formatting, you have to use a Culture.

See: http://msdn.microsoft.com/en-us/library/shxtf045%28v=vs.110%29.aspx

double value = -16325.62015;
// Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
// Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")));
// Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")));