2011-08-13 41 views

回答

4

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

您可以将UserControlGrid结合其宽度/高度,以固定页面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> 
+0

TS,明确hax ... –

+0

只有一个问题Meleak,MyUserControl有一个Results属性。 在window_load中,我有一个公共字段,其中包含一个列表。我需要将该列表传递给MyUserControl.Results。我应该使用绑定或数据上下文? –

+0

@ oscar.fimbres:对于当前的问题,这听起来有些超出上下文,所以我不能100%确定我明白你想要做什么。但是Bindings只能用于属性而不是字段,因此如果在'UserControl'中有一个名为Results的依赖属性,那么你可以使用DataContext,RelativeSource或ElementName将它绑定到'Window'中的属性,具体取决于你的场景。你也应该在'Window'中实现'INotifyPropertyChanaged',这样一旦属性发生变化,绑定就会被更新 –