How can I center my page in the document viewer?

落爺英雄遲暮 提交于 2019-12-11 03:08:49

问题


I'm using a document to show a user control. Some people from here helped me: How can I put an user control inside a document viewer?

But the user control appers in the corner, and I'd like to print it, but a little bit more central.


回答1:


Repeating my updated answer from the other question..

You can place the UserControl in a Grid which binds its Width/Height to the FixedPage ActualWidth/ActualHeight to achieve centering

<DocumentViewer>
    <FixedDocument>
        <PageContent>
            <FixedPage>
                <Grid Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type FixedPage}},
                                      Path=ActualWidth}"
                      Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type FixedPage}},
                                       Path=ActualHeight}">
                    <local:MyUserControl HorizontalAlignment="Center"
                                         VerticalAlignment="Center"/>
                </Grid>
            </FixedPage>
        </PageContent>
    </FixedDocument>
</DocumentViewer>


来源:https://stackoverflow.com/questions/7047927/how-can-i-center-my-page-in-the-document-viewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!