在 UI 上显示反斜杠而不是货币符号
Show backslash instead of currency symbol on UI
我试图在 WPF TextBlock 上打印 \,但我得到的是货币符号。我认为这是因为系统是 CJK Windows,所以添加了文化信息代码。
CultureInfo useng = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = useng;
Thread.CurrentThread.CurrentUICulture = useng;
问题仍然存在,我 运行 没有想法,所以我使用了这个非常糟糕的解决方法。
CultureInfo useng = new CultureInfo("en-US");
useng.NumberFormat.CurrencySymbol = "\";
Thread.CurrentThread.CurrentCulture = useng;
Thread.CurrentThread.CurrentUICulture = useng;
我想知道是否有解决此问题的正确方法。
更新 TextBlock 的代码在 Timer 对象中使用 TextBlock.Text 并从 List 中获取 Char 对象,并将 Char 声明为 '\\'
Dispatcher.Invoke(new Action(() => { tb.Text = "" + listCharEnumerator.Current; }), System.Windows.Threading.DispatcherPriority.Render);
Code in full available on github. Small project, really.
请注意,上述解决方法不适用于此 b运行ch。
你的问题的根源是 listCharEnumerator.Current
在你等待调度员 运行 时发生了变化,所以当调度员有机会 运行 时它已经离开了的 \
并移至可能是集合中的最后一项(可能是货币符号)。
解决此问题的方法是在调度程序之前将枚举器的值放入局部变量,然后在调度程序内部使用局部变量。
var temp = listCharEnumerator.Current;
Dispatcher.Invoke(new Action(() => { tb.Text = "" + temp; }), System.Windows.Threading.DispatcherPriority.Render);
我试图在 WPF TextBlock 上打印 \,但我得到的是货币符号。我认为这是因为系统是 CJK Windows,所以添加了文化信息代码。
CultureInfo useng = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = useng;
Thread.CurrentThread.CurrentUICulture = useng;
问题仍然存在,我 运行 没有想法,所以我使用了这个非常糟糕的解决方法。
CultureInfo useng = new CultureInfo("en-US");
useng.NumberFormat.CurrencySymbol = "\";
Thread.CurrentThread.CurrentCulture = useng;
Thread.CurrentThread.CurrentUICulture = useng;
我想知道是否有解决此问题的正确方法。
更新 TextBlock 的代码在 Timer 对象中使用 TextBlock.Text 并从 List 中获取 Char 对象,并将 Char 声明为 '\\'
Dispatcher.Invoke(new Action(() => { tb.Text = "" + listCharEnumerator.Current; }), System.Windows.Threading.DispatcherPriority.Render);
Code in full available on github. Small project, really.
请注意,上述解决方法不适用于此 b运行ch。
你的问题的根源是 listCharEnumerator.Current
在你等待调度员 运行 时发生了变化,所以当调度员有机会 运行 时它已经离开了的 \
并移至可能是集合中的最后一项(可能是货币符号)。
解决此问题的方法是在调度程序之前将枚举器的值放入局部变量,然后在调度程序内部使用局部变量。
var temp = listCharEnumerator.Current;
Dispatcher.Invoke(new Action(() => { tb.Text = "" + temp; }), System.Windows.Threading.DispatcherPriority.Render);