如何使我的页面在文档查看器中居中?

osc*_*res 2 c# wpf layout xaml documentviewer

我正在使用文档来显示用户控件。这里的一些人帮助了我:如何将用户控件放入文档查看器中?

但用户控件出现在角落里,我想打印它,但更中心一点。

Fre*_*lad 5

重复我在另一个问题中的更新答案..

您可以将 放在UserControla 中Grid,将其宽度/高度绑定到固定页面 ActualWidth/ActualHeight 以实现居中

<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>
Run Code Online (Sandbox Code Playgroud)