0

I've created a special purpose rich text editor in Wpf. There, I have two buttons which control number digit substitution, converting 123 to ١٢٣ or vice versa.

The first button does this:

targetRange.ApplyPropertyValue(NumberSubstitution.CultureOverrideProperty, new CultureInfo("fa-IR"));
targetRange.ApplyPropertyValue(NumberSubstitution.CultureSourceProperty, NumberCultureSource.Override);
targetRange.ApplyPropertyValue(NumberSubstitution.SubstitutionProperty, NumberSubstitutionMethod.Traditional);

to show all digits in the selection as arabic-hindi digist ١٢٣ and the second does:

targetRange.ApplyPropertyValue(NumberSubstitution.CultureOverrideProperty, new CultureInfo("en-US"));
targetRange.ApplyPropertyValue(NumberSubstitution.CultureSourceProperty, NumberCultureSource.Override);
targetRange.ApplyPropertyValue(NumberSubstitution.SubstitutionProperty, NumberSubstitutionMethod.European);

to show them as Arabic-European digits 123.

I'm trying to create a silverlight equivalent of this editor. It seems that I'm unable to perform the same task in silverlight. Any google searches about number digit substitution in silverlight yield no related results.

Can you please point me in the right direction?

PS: Changing the CultureInfo is not an option, as I need to mix these numbers in the same application.

Alireza
  • 5,421
  • 5
  • 34
  • 67

1 Answers1

0

Can you not just use the Int32.ToString(String, IFormatProvider) method? Maybe something like this:

int value = GetYourIntValue();
string newValue = value.ToString(new CultureInfo("fa-IR"));
Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • Thank, but no, this is happening to a rich text entered by the user. – Alireza Jan 08 '14 at 09:33
  • 1
    So you can't extract the text value from `targetRange` and then set it to the `newValue`? – Sheridan Jan 08 '14 at 09:40
  • I can, but it will incur some drawbacks, for instance it will become more difficult to search for the text in the database. Actually, with digit substitution (which happens automatically in some language settings) the digits are stored with the same unicode values as 123, but displayed as ١٢٣ – Alireza Jan 09 '14 at 18:35