FlowDocument FirstBlock保证金顶部被忽略 [英] FlowDocument FirstBlock Margin Top is ignored

查看:81
本文介绍了FlowDocument FirstBlock保证金顶部被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给予

<RichTextBox>

< FlowDocument> <部分保证金="30"> <段落> < Run> Hello World!</Run> </段落> </部分> </FlowDocument>

<FlowDocument> <Section Margin="30"> <Paragraph> <Run>Hello World!</Run> </Paragraph> </Section> </FlowDocument>

</RichTextBox>


为什么FlowDocument忽略了FirstBlock的上边距?似乎将其设置为0.添加的后续块将按预期正确设置边距.如果是设计使然,那么我似乎无法在文档中找到这样做的原因. 我尝试深入研究参考源,但似乎找不到将Margin设置为0的位置.

Why is FlowDocument ignoring the FirstBlock's Top margin? It looks like it is setting it to 0. The succeeding blocks that are added sets the margin correctly as expected. I can't seem to find in the documentation why it's doing that if it is by designed. I tried looking deep into the reference source but can't seem to find the place where it is setting the Margin to 0.

花了更多时间研究参考文献,我发现了这一点

Spending more time digging into the reference, and I found this

internal void FormatParaFinite(
            ContainerParaClient paraClient,     // IN:
            IntPtr pbrkrecIn,                   // IN:  break record---use if !IntPtr.Zero
            int fBRFromPreviousPage,            // IN:  break record was created on previous page
            int iArea,                          // IN:  column-span area index
            IntPtr footnoteRejector,            // IN:
            IntPtr geometry,                    // IN:  pointer to geometry
            int fEmptyOk,                       // IN:  is it OK not to add anything?
            int fSuppressTopSpace,              // IN:  suppress empty space at the top of the page
            uint fswdir,                        // IN:  current direction
            ref PTS.FSRECT fsrcToFill,          // IN:  rectangle to fill
            MarginCollapsingState mcs,          // IN:  input margin collapsing state
            PTS.FSKCLEAR fskclearIn,            // IN:  clear property that must be satisfied
            PTS.FSKSUPPRESSHARDBREAKBEFOREFIRSTPARA fsksuppresshardbreakbeforefirstparaIn,
                                                // IN: suppress breaks at track start?
            out PTS.FSFMTR fsfmtr,              // OUT: result of formatting the paragraph
            out IntPtr pfspara,                 // OUT: pointer to the para data
            out IntPtr pbrkrecOut,              // OUT: pointer to the para break record
            out int dvrUsed,                    // OUT: vertical space used by the para
            out PTS.FSBBOX fsbbox,              // OUT: para BBox
            out IntPtr pmcsclientOut,           // OUT: margin collapsing state at the bottom
            out PTS.FSKCLEAR fskclearOut,       // OUT: ClearIn for the next paragraph
            out int dvrTopSpace)            


And inside the method it has this 

 // Top margin collapsing. If suppresing top space, top margin is always 0.
 MarginCollapsingState.CollapseTopMargin(PtsContext, mbp, mcs, out mcsContainer, out marginTop);
 if (PTS.ToBoolean(fSuppressTopSpace))
 {
  marginTop = 0;
 }

这背后的原因是什么?是否与定义的CSS规范相同的原因 此处?

What is the reason behind this? Is it the same reason with the CSS specification defined here?

为什么第一个块不能执行与FlowDocument中添加的后续块相同的行为?我想不出为什么不允许设置最高边距的原因.分页,打印,字形问题?

Why is the first block can't do the same behavior like the succeeding blocks that are added in the FlowDocument? I can't think of a reason why it won't allow top margin being set. Pagination, printing, glyph issues? 

<FlowDocument>
       <Section Margin="30">
              <Paragraph>
                        <Run>Hello World!</Run>
              </Paragraph>
        </Section>
       <Section Margin="30">
              <Paragraph>
                        <Run>Hello World!</Run>
              </Paragraph>
        </Section>
</FlowDocument>

上面的代码片段证明了第二部分是唯一遵守最高边距的部分.


Above code snippet proves that the second section is the only one that obeys the top margin.


推荐答案

是的,两个相邻段落的边距将折叠".在两个边距中取较大者: http://msdn.microsoft.com/en-us/library/ms749187 (v = vs.110).aspx .各节的边距"属性指定各节之间的边距.

Yes, margins for two adjacent paragraphs will "collapse" to the larger of the two margins: http://msdn.microsoft.com/en-us/library/ms749187(v=vs.110).aspx. The Margin property of the Sections specifies the margin between the Sections.

要设置第一节的顶部边距,可以使用FlowDocument的PagePadding属性:

To set the top margin for the first Section, you could use the PagePadding Property of the FlowDocument:

<FlowDocument PagePadding="0 30 0 0">
                <Section Margin="30">
                    <Paragraph>
                        <Run>Hello World!</Run>
                    </Paragraph>
                </Section>
                <Section Margin="30">
                    <Paragraph>
                        <Run>Hello World!</Run>
                    </Paragraph>
                </Section>
            </FlowDocument>



这篇关于FlowDocument FirstBlock保证金顶部被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆