问题
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