Note that there are some explanatory texts on larger screens.

plurals
  1. POC# WPF Converting english numbers to arabic numbers
    primarykey
    data
    text
    <p>I need to display an english double in arabic numerical characters for an application I am working on.</p> <p>Here is an example class that holds the double:</p> <pre><code>public class Class1 { private double someDouble = 0.874; public double SomeDouble { get { return someDouble; } } } </code></pre> <p>I want to convert the value of SomeDouble to a percentage displayed in Arabic numeric characters at runtime. Here is some quick XAML I've been using as a test:</p> <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ArabicNumbers" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Class="ArabicNumbers.Window1" Title="Window1" Height="300" Width="300"&gt; &lt;Window.Resources&gt; &lt;local:Class1 x:Key="Class1Instance" /&gt; &lt;local:DoubleValueConverter x:Key="doubleValueConverter" /&gt; &lt;/Window.Resources&gt; &lt;Grid DataContext="{Binding Source={StaticResource Class1Instance}}"&gt; &lt;TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" TextWrapping="Wrap" Margin="10" Text="{Binding SomeDouble, Converter={StaticResource doubleValueConverter}, Mode=Default}"/&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>And my test value converter, DoubleValueConverter:</p> <pre><code>public class DoubleValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double valueAsDouble = (double)value; return valueAsDouble.ToString("P1", culture); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } </code></pre> <p>In the code behind for the window, I set the Language property to the current culture which is "ar-SA". This would seem to be a requirement as this changes the value of the culture parameter in DoubleValueConverter.</p> <pre><code>public partial class Window1 : Window { public Window1() { Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name); InitializeComponent(); } } </code></pre> <p>This converter provides the correct formatting properties, ie the decimal separator, however I need these numbers to be output as Arabic characters rather than "87,4%".</p> <p>Does anyone have any suggestions on a simple way to do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload