WPF Flowdocument - 防止 % 符号前换行
我有一个 FlowDocument 为客户生成文档,但它出现了他们不喜欢的换行符。有什么方法可以标记应避免换行的文本部分吗?像这样的事情:
<Paragraph>Here is a paragraph where there should be <span NoLineBreak=True>no line break</span> in a certain part.</Paragraph>
显然,Span 没有 NoLineBreak 属性,但我想知道是否有一些可用的等效功能,或者是否有人可以让我开始实现 SpanWithNoLineBreak 类或 RunWithNoLineBreak 类?
更新 实际上,我遇到的一个问题是百分号,其中甚至没有空格:
<Paragraph>When I print and ½% I want the one-half and '%' symbols to not line break between them.</Paragraph>
& #x00BD;是 ½ 符号的 unicode。我在 1/2 和 % 之间换行,即使它们之间没有空格。
I've got a FlowDocument generating a document for a client, and it's getting a line break that they don't like. Is there any way to mark a section of text that it should avoid line breaks? Something like this:
<Paragraph>Here is a paragraph where there should be <span NoLineBreak=True>no line break</span> in a certain part.</Paragraph>
Obviously, a Span doesn't have a NoLineBreak property, but I'm wondering if there's some equivilant functionality available, or if someone can get me started on a way of implementing a SpanWithNoLineBreak class or RunWithNoLineBreak class?
UPDATE
Actually, one issue I'm having is with a percent sign, where there isn't even a space:
<Paragraph>When I print and ½% I want the one-half and '%' symbols to not line break between them.</Paragraph>
The & #x00BD; is the unicode for a ½ symbol. I'm getting a line wrap between the 1/2 and the % even though there's no space between them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Unicode 字符“Word Joiner”(U+2060) 是就是为了这个目的。它“通常不会产生任何空格,但禁止在其两侧出现换行符”(维基百科)。将其放置在 U+00BD 和 '%' 之间以防止它们之间出现换行符。
不幸的是,WPF(或者可能是 Windows 提供的典型字体)不能正确支持它,而是将其呈现为方框。作为替代方案,您可以使用 U+FEFF;现在不推荐使用此字符作为零宽度不间断空格(它保留用作字节顺序标记),但它对我来说可以作为换行防止器。
最后,还有一些其他字符也可以用于此目的: U +202F(狭窄的无中断空间)也可以防止中断,但也会呈现为非常薄的空间。 U+00A0(无中断空格)可防止中断和显示作为一个正常的空间。
The Unicode character "Word Joiner" (U+2060) is intended for just this purpose. It "does not normally produce any space but prohibits a line break on either side of it" (Wikipedia). You place it between U+00BD and '%' to prevent a line break between them.
Unfortunately, WPF (or perhaps the typical fonts supplied with Windows) don't support it properly, and instead render it as a square box. As an alternative, you could use U+FEFF; the use of this character as a zero-width non-breaking space is now deprecated (it's reserved for use as a byte-order mark), but it worked as a line-break-preventer for me.
Finally, there are some other characters that can also be used for this purpose: U+202F (narrow no-break space) also prevents breaking, but also renders as a very thin space. U+00A0 (no-break space) prevents breaking and displays as a normal space.
尝试将空格替换为不间断空格。
编辑:嗯,总是有一个备用计划,即使用 TextWrapping=NoWrap 将 TextBlocks 放入 FlowDocument 中,但我会尝试找到更好的方法......
Try replacing the spaces with non-breaking spaces.
EDIT: Well there's always the backup plan of just putting in TextBlocks in your FlowDocument with TextWrapping=NoWrap, but I'd try to find a better way...