2
我正在使用文档来显示用户控件。一些来自这里的人帮助了我:How can I put an user control inside a document viewer?如何将我的页面置于文档查看器中?
但是用户控件出现在角落,我想打印它,但稍微中央。
我正在使用文档来显示用户控件。一些来自这里的人帮助了我:How can I put an user control inside a document viewer?如何将我的页面置于文档查看器中?
但是用户控件出现在角落,我想打印它,但稍微中央。
重复从另一个问题我的答案更新..
您可以将UserControl
在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>
TS,明确hax ... –
只有一个问题Meleak,MyUserControl有一个Results属性。 在window_load中,我有一个公共字段,其中包含一个列表。我需要将该列表传递给MyUserControl.Results。我应该使用绑定或数据上下文? –
@ oscar.fimbres:对于当前的问题,这听起来有些超出上下文,所以我不能100%确定我明白你想要做什么。但是Bindings只能用于属性而不是字段,因此如果在'UserControl'中有一个名为Results的依赖属性,那么你可以使用DataContext,RelativeSource或ElementName将它绑定到'Window'中的属性,具体取决于你的场景。你也应该在'Window'中实现'INotifyPropertyChanaged',这样一旦属性发生变化,绑定就会被更新 –