开发者

WPF: How to justify all lines within paragraphs (lines with line breaks too)

开发者 https://www.devze.com 2022-12-28 04:02 出处:网络
i have a some paragraphs within a FlowDocument, and what i need is to justify all lines (even lines with line breaks)

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 开发者_JAVA技巧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


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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消