Wpf数字替换 [英] Wpf digit substitution

查看:83
本文介绍了Wpf数字替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

推荐答案

好的,有一种简单的方法,你可以伪造这相对容易但根据替代字符的宽度以及它们如何映射到当前字符的宽度,可能有一个有点不和谐的界面。诀窍是将两个TextBox叠加在一起。顶部接受输入但实际上是不可见的。下面的那个是显示您的实际内容的那个。 XAML看起来有点像这样:
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:
<Grid>
  <TextBox Text="{Binding ConvertedText}" />
  <TextBox Foreground="Transparent" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" Background="Transparent" />
</Grid>

现在,这背后的ViewModel可能不会更简单。实际上,当您更改Text属性时,它会自动触发转换代码。

Now, the ViewModel behind this couldn't be simpler. Effectively, when you change the Text property, it automatically triggers the conversion code.

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.


这篇关于Wpf数字替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆