WPF:如何对齐段落中的所有行(也有换行符的行)

发布于 2024-08-30 16:17:33 字数 853 浏览 4 评论 0原文

我在 FlowDocument 中有一些段落,我需要的是证明所有行(甚至是带有换行符的行)的合理性,

这是一个代码示例:

 <Paragraph TextAlignment="Justify">
"One of the most important operations necessary when text materials
are prepared for printing or display is the task of dividing long
paragraphs into individual lines.<LineBreak/>
When this job has been done well,
people will not be aware of the fact that the words they are reading
have been broken apart arbitrarily and placed into a somewhat rigid
and unnatural rectangular framework; but if the job has been done
poorly, readers will be distracted by bad breaks that interrupt
their train of thought."
</Paragraph>

上面的输出不会证明有换行符的行合理,该行将是左对齐,我需要的是所有行的宽度相同,

这如何实现?

(请注意,如果段落有换行符并且设置为对齐,则所需的输出与 ms word 中可实现的输出相同,例如,如果一行上有 3 个单词,则左侧有 1 个单词,中间有 1 个单词右边有一个)

谢谢, 山姆

i have a some paragraphs within a FlowDocument, and what i need is to justify all lines (even lines with line breaks)

Here's a code sample:

 <Paragraph TextAlignment="Justify">
"One of the most important operations necessary when text materials
are prepared for printing or display is the task of dividing long
paragraphs into individual lines.<LineBreak/>
When this job has been done well,
people will not be aware of the fact that the words they are reading
have been broken apart arbitrarily and placed into a somewhat rigid
and unnatural rectangular framework; but if the job has been done
poorly, readers will be distracted by bad breaks that interrupt
their train of thought."
</Paragraph>

The output of the above will not justify the line that has a line break, this line will be aligned left, what i need is a same-width lines for all lines

How could this be achieved?

(Note that the desired output is the same output achievable in ms word if a paragraph has line breaks and is set to justify, for example if we have 3 words on a line we'll have 1 word on the left, one in the center and one on the right)

Thanks,
Sam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长伴 2024-09-06 16:17:33

我不认为你能达到你想要的目标。即使您将 替换为一个关闭的段落(我知道您不想要):

<Paragraph TextAlignment="Justify">
One of the most important operations necessary when text materials
are prepared for printing or display is the task of dividing long
paragraphs into individual lines.
</Paragraph>
<Paragraph TextAlignment="Justify">
When this job has been done well,
people will not be aware of the fact that the words they are reading
have been broken apart arbitrarily and placed into a somewhat rigid
and unnatural rectangular framework; but if the job has been done
poorly, readers will be distracted by bad breaks that interrupt
their train of thought.
</Paragraph>

该段落的最后一行是左对齐的。

I don't think you can achieve what you want. Even if you replace the <LineBreak/> with a close paragraph (which I know you don't want):

<Paragraph TextAlignment="Justify">
One of the most important operations necessary when text materials
are prepared for printing or display is the task of dividing long
paragraphs into individual lines.
</Paragraph>
<Paragraph TextAlignment="Justify">
When this job has been done well,
people will not be aware of the fact that the words they are reading
have been broken apart arbitrarily and placed into a somewhat rigid
and unnatural rectangular framework; but if the job has been done
poorly, readers will be distracted by bad breaks that interrupt
their train of thought.
</Paragraph>

the last line of the paragraph is left justified.

離殇 2024-09-06 16:17:33

这是否是您想要做的事情:

<Paragraph Margin="5,5,5,5"> <!--You can assign margin here or below to give you the spacing needed-->
<!--You can set width as need, but new line can be done in a textblocks LineBreak-->
<TextBlock TextAlignment ="Justify" TextWrapping="Wrap" Width="150"> 
    One of the most <LineBreak/>important operations necessary when text materials 
    are prepared for printing or display is the task of dividing long
    paragraphs into individual lines.
</TextBlock>                               

希望有帮助...

Is this what you might be wanting todo:

<Paragraph Margin="5,5,5,5"> <!--You can assign margin here or below to give you the spacing needed-->
<!--You can set width as need, but new line can be done in a textblocks LineBreak-->
<TextBlock TextAlignment ="Justify" TextWrapping="Wrap" Width="150"> 
    One of the most <LineBreak/>important operations necessary when text materials 
    are prepared for printing or display is the task of dividing long
    paragraphs into individual lines.
</TextBlock>                               

Hope that helps...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文