c# - 为什么感叹号出现在文字前面

标签 c# .net wpf

我只是用一些包含 ! (感叹号)在最后。和 !出现在文本前面。

所以代替

some text!

我明白了

!some text

这怎么可能?

有什么线索吗?

谢谢!


代码

  TextBlock tb = new TextBlock();

  tb.Text = Text;

  lstItems.Children.Add(tb); // lstItems is a StackPanel

最佳答案

TextBlock 的祖先很可能将其 FlowDirection 设置为 RightToLeft。尝试将其重置为 LeftToRight:

tb.FlowDirection = FlowDirection.LeftToRight;

编辑:原因解释起来有点复杂;这与如何bi-directional text有关被渲染。来自维基百科:

Punctuation characters […] can appear in both LTR and RTL scripts. They are called "weak" characters because they do not contain any directional information. So it is up to the software to decide in which direction these "weak" characters will be placed.

WPF 将您的 ! 与文本的其余部分分开,并将其放置在您的方向流中(在本例中,向 right left ).

关于c# - 为什么感叹号出现在文字前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10805735/

相关文章:

wpf - 使用迁移到 LocalDB 的 CodeFirst,我可以指定*在哪里*创建数据库吗?

c# - 在 WCF 服务应用程序项目中初始化?

c# - 将 float 组转换为字符串的最快方法是什么?

c# - WPF 使用数据绑定(bind)从日期选择器显示年龄

.net - wcf tcp async streamed 是可能的吗?

c# - 将 Access 数据库表加载到数据表

c# - WPF(C#) 中文本框中的不同字体大小和方向

c# - FrameworkPropertyMetadata 的构造函数中的默认值对象实际上做了什么?

c# - 识别网络中的工作站 c#

C#:实现IDisposable接口(interface)时Dispose方法的内容应该是什么