【问题标题】:How can I center my page in the document viewer?如何在文档查看器中居中我的页面?
【发布时间】:2011-08-13 09:50:55
【问题描述】:

我正在使用文档来显示用户控件。这里的一些人帮助了我:How can I put an user control inside a document viewer?

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

【问题讨论】:

    标签: c# wpf xaml layout documentviewer


    【解决方案1】:

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

    您可以将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>
    

    【讨论】:

    • 只有一个问题 Meleak,MyUserControl 有一个 Results 属性。在 window_load 中,我有一个包含列表的公共字段。我需要将该列表传递给 MyUserControl.Results。我应该使用绑定还是数据上下文?
    • @oscar.fimbres:这听起来有点脱离当前问题的背景,所以我不能 100% 确定我理解你想要做什么。但是 Bindings 仅适用于属性,而不适用于开头的字段,因此如果您在 UserControl 中有一个名为 Results 的依赖属性,那么您可以根据您的场景使用 DataContext、RelativeSource 或 ElementName 将其绑定到 Window 中的属性.您可能还应该在您的Window 中实现INotifyPropertyChanaged,以便在属性更改后更新绑定
    猜你喜欢
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-02-29
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 2016-08-24
    相关资源
    最近更新 更多