I need to display an english double in arabic numerical characters for an application I am working on.
Here is an example class that holds the double:
public class Class1
{
private double someDouble = 0.874;
public double SomeDouble
{
get { return someDouble; }
}
}
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:
<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">
<Window.Resources>
<local:Class1 x:Key="Class1Instance" />
<local:DoubleValueConverter x:Key="doubleValueConverter" />
</Window.Resources>
<Grid DataContext="{Binding Source={StaticResource Class1Instance}}">
<TextBlock
HorizontalAlignment="Left"
VerticalAlignment="Top"
TextWrapping="Wrap"
Margin="10"
Text="{Binding SomeDouble, Converter={StaticResource doubleValueConverter}, Mode=Default}"/>
</Grid>
And my test value converter, DoubleValueConverter:
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();
}
}
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.
public partial class Window1 : Window
{
public Window1()
{
Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name);
InitializeComponent();
}
}
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%".
Does anyone have any suggestions on a simple way to do this?