Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
When user type English words, I want all numeric characters being  Arabic font(or shape).
(something like the Word app you can do it by going to Options ---> Advanced --->
Show document content ---> Numeral)

for example I want when user type "2", but see "٢".

Is it Possible?


What I have tried:

I don't want use CultureInfo, because it makes some problem for my application
Posted
Updated 12-Jan-18 20:02pm
v2
Comments
Dotnet_Dotnet 9-Jan-18 12:27pm    
sir If you use unicode charector or conversion then can possible

1 solution

Okay, there is a simple way that you can "fake" this relatively easy but depending on the width of the alternate characters and how they map into the width of the current characters, there may be a bit of a jarring interface. The trick is to overlay two TextBoxes over each other. The top one accepts the input but is, effectively, invisible. The one underneath is the one that displays your actual content. The XAML looks a bit like this:
XML
<Grid>
  <TextBox Text="{Binding ConvertedText}" />
  <TextBox Foreground="Transparent" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" Background="Transparent" />
</Grid>
Now, the ViewModel behind this couldn't be simpler. Effectively, when you change the Text property, it automatically triggers the conversion code.
C#
public string Text
{
  get => _text;
  set
  {
    if (_text != value)
    {
      _text = value;
      ConvertedText = _text.Replace("1", "y");
      OnPropertyChanged();
    }
  }
}

public string ConvertedText
{
  get => _convertedText;
  set
  {
    if (_convertedText != value)
    {
      _convertedText = value;
      OnPropertyChanged();
    }
  }
}
And that's it, a potentially simple solution to your problem.
 
Share this answer
 
Comments
Richard Deeming 10-Jan-18 12:59pm    
You might want to set Focusable="False" on the first textbox, so that users who tab through the form don't end up typing in the wrong box. :)
Pete O'Hanlon 10-Jan-18 15:50pm    
That's true, missed it out altogether but as I just typed the code out in the CP editor I'm pleased I got what I wrote correct.
Member 10527566 13-Jan-18 1:56am    
Thanks, but i want a general solution , I have many TextBox, TexBlock, GridView.
Pete O'Hanlon 13-Jan-18 5:09am    
You are going to have to look at writing something like a behaviour then, that is going to put Runs in place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900