Wpf Flowdocument未使用全宽/全高

Wpf Flowdocument未使用全宽/全高,wpf,resize,flowdocument,Wpf,Resize,Flowdocument,我有一个FlowDocument,我想填充整个窗口的宽度和高度。我尝试过使用FlowDocumentPageViewer(运气不好),现在正在使用DocumentPageView。我仍然无法让它停靠/填满整个空间;它只是坐在中间,它能创造的最小尺寸(有意义吗?)< /P> 这是我的密码: public DocumentPageView GetPage() { FlowDocumentPageViewer viewer = new FlowDocumentPageVie

我有一个FlowDocument,我想填充整个窗口的宽度和高度。我尝试过使用
FlowDocumentPageViewer
(运气不好),现在正在使用
DocumentPageView
。我仍然无法让它停靠/填满整个空间;它只是坐在中间,它能创造的最小尺寸(有意义吗?)< /P> 这是我的密码:

   public DocumentPageView GetPage()
   {
        FlowDocumentPageViewer viewer = new FlowDocumentPageViewer();           
        StreamReader reader = new StreamReader(location);
        string data = reader.ReadToEnd();
        reader.Close();
        string xamlData = HtmlToXamlConverter.ConvertHtmlToXaml(data, true);
        FlowDocument result = (FlowDocument)System.Windows.Markup.XamlReader.Load(new MemoryStream(System.Text.UnicodeEncoding.Default.GetBytes(xamlData)));

        viewer.Document = result;
        viewer.VerticalAlignment = VerticalAlignment.Center;
        viewer.HorizontalAlignment = HorizontalAlignment.Center;

        DocumentPageView pageView = new DocumentPageView();
        pageView.VerticalAlignment = VerticalAlignment.Center;
        pageView.HorizontalAlignment = HorizontalAlignment.Center;
        pageView.Stretch = System.Windows.Media.Stretch.Uniform;
        pageView.PageNumber = 0;
        pageView.StretchDirection = StretchDirection.Both;
        pageView.DocumentPaginator = ((IDocumentPaginatorSource)result).DocumentPaginator;
        return pageView;
   }
请注意,此代码包含我的两种方法的组合,但当前仅使用
DocumentPageView
。这是从我的HTML源代码创建的Xaml:

<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Paragraph TextAlignment="center" FontSize="22pt" FontFamily="arial">Test Paragraph</Paragraph>
<Paragraph TextAlignment="center" FontFamily="arial">Test second paragraph</Paragraph>
</FlowDocument>

测试段
测试第二段

如果我调整字体大小,内容只会垂直调整大小(请注意,拉伸方向设置为两个方向)。有什么想法吗?

能否指定在何处以及如何使用GetPage()方法的结果?是xbap还是桌面应用程序

我这样问是因为以下文档正好显示在:


测试段
测试第二段

PS:如果它是一个桌面应用程序,你总是可以从Pete Blois表中找到谁引起了问题。

更新:它是一个桌面应用程序,getpage()结果被发布到一个网格中,该网格可以完美地停靠/填充

<Window x:Class="GreenWebPlayerWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="Auto" Width="Auto" WindowStyle="None" WindowState="Maximized" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" Closing="Window_Closing">
    <Grid Width="Auto" Height="Auto" Name="TransitionContainer" Background="White" Margin="0">
        //here the result from GetPage() method is inserted
    </Grid>
</Window>

//这里插入GetPage()方法的结果
(此评论来自另一个帐户)

@Anvaka:我所说的完全正确的意思是文档应该“停靠在容器中”,即字体应该调整大小,它应该在高度和宽度上填充容器。现在我在考虑这个问题,对于一个flowdocument来说,这似乎不是一个合适的行为


当我将流文档放在容器中时,它位于父容器的中间(到目前为止还不错)。但是父容器没有填充其父容器,因此当我缩放或更改字体大小时,我希望documentPageView容器的宽度和高度增加,但保持居中。

我对
FlowDocumentScrollView
有类似的问题,但此解决方案似乎也适用于
FlowDocumentPageView

FlowDocument
居中,因为它的
PagePadding
属性设置为
auto,auto,auto
。将PagePadding设置为
0
可修复此行为

<FlowDocumentScrollViewer VerticalScrollBarVisibility="Auto">
    <FlowDocument PagePadding="0">
    </FlowDocument>
</FlowDocumentScrollViewer>

以下几行导致元素自身居中(与拉伸不同):

您可以安全地删除它们,因为此处的默认对齐方式是“拉伸”

如果仍要使查看器居中,请明确定义页面大小(请记住,每英寸有96个点,边距和页面大小以点为单位设置):

宽度=96*8.5


Height=96*11

snoop工具说我的“DocumentPageHost”的宽度只有816px,这只是我分辨率的一半。如何改变这一点。我打赌这是反映在DocumentPageView上的一个,它的宽度也只有816(811363636)更新:我试图在XamlPad中查看它,但显示不正确。也许是我期望太高了。内容是左上对齐的,而不是居中填充…:)现在我意识到,我的“完全正确”不是你的。你想得到什么样的确切布局?使用预设来查看我的帖子。这不是评论。作为对你问题的编辑比作为答案更有用——事实并非如此。。
<FlowDocumentScrollViewer VerticalScrollBarVisibility="Auto">
    <FlowDocument PagePadding="0">
    </FlowDocument>
</FlowDocumentScrollViewer>
viewer.VerticalAlignment = VerticalAlignment.Center;
viewer.HorizontalAlignment = HorizontalAlignment.Center;
pageView.VerticalAlignment = VerticalAlignment.Center;
pageView.HorizontalAlignment = HorizontalAlignment.Center;