【发布时间】:2011-08-13 09:50:55
【问题描述】:
我正在使用文档来显示用户控件。这里的一些人帮助了我:How can I put an user control inside a document viewer?
但是用户控件出现在角落里,我想打印它,但更中心一点。
【问题讨论】:
标签: c# wpf xaml layout documentviewer
我正在使用文档来显示用户控件。这里的一些人帮助了我:How can I put an user control inside a document viewer?
但是用户控件出现在角落里,我想打印它,但更中心一点。
【问题讨论】:
标签: c# wpf xaml layout documentviewer
从另一个问题重复我的更新答案..
您可以将UserControl 放置在Grid 中,该Grid 将其宽度/高度绑定到FixedPage 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>
【讨论】:
UserControl 中有一个名为 Results 的依赖属性,那么您可以根据您的场景使用 DataContext、RelativeSource 或 ElementName 将其绑定到 Window 中的属性.您可能还应该在您的Window 中实现INotifyPropertyChanaged,以便在属性更改后更新绑定