Flowdocument 未使用完整宽度/高度
我有一个 FlowDocument,我想填充窗口的整个宽度和高度。我尝试过使用 FlowDocumentPageViewer
(没有运气),现在使用 DocumentPageView
。我仍然无法让它停靠/填满整个空间;它只是坐在中间,以它可以创建的最小尺寸(有意义吗?)
这是我的代码:
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>
如果我调整字体大小,则内容只会垂直调整大小(请注意,拉伸方向设置为两个方向)。有什么想法吗?
I have a FlowDocument which I want to fill the entire width and height of my window. I have tried using the FlowDocumentPageViewer
(no luck) and am now using a DocumentPageView
. I still can't get it to dock/fill the entire space; it's just sitting in the middle, in the minimum size it can create (does it make sense?)
Here is my code:
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;
}
Please note that this code contains the combination of my two methods but only the DocumentPageView
is currently used. This is the Xaml that is created from my HTML source:
<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>
If I resize the fonts the content is only resized vertically (please note that the stretch direction is set to both). Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在
FlowDocumentScrollView
上遇到了类似的问题,但此解决方案似乎也适用于FlowDocumentPageView
:FlowDocument
居中,因为它是PagePadding< /code> 属性设置为
auto,auto,auto,auto
。将 PagePadding 设置为0
可修复此行为。I had a similar problem with
FlowDocumentScrollView
, but this solution also seems to work withFlowDocumentPageView
:The
FlowDocument
is centered because it'sPagePadding
property is set toauto,auto,auto,auto
. Setting PagePadding to0
fixes this behavior.以下几行导致元素居中(这与拉伸不同):
您可以安全地删除它们,因为此处的默认对齐方式是拉伸。
如果您仍想让查看器居中,请显式定义页面大小(请记住,一英寸有 96 点,边距和页面大小以点为单位设置):
宽度= 96 * 8.5
高度= 96 * 11
The following lines are causing your elements to center themselves (which is not the same as stretch):
You can safely remove them, as the default alignment here is Stretch.
If you still want to center the viewer, explicitly define the page size (remember, there are 96 points in an inch, and the Margin and PageSize are set in points):
Width= 96 * 8.5
Height= 96 * 11
您能否指定在何处以及如何使用 GetPage() 方法的结果?是 xbap 还是桌面应用程序?
我这么问是因为以下文档在 Kaxaml 中显示得完全正确:
PS:如果它是在桌面应用程序中,您始终可以通过 Pete Blois 的 Snoop 工具 找到导致问题的人。
Could you specify where and how do you use the result of your GetPage() method? Is it xbap or desktop application?
I'm asking this, because the following document is displayed just perfectly right in Kaxaml:
PS: If it's a desktop application you can always find who causes problems by Snoop tool, form Pete Blois.
更新:它是一个桌面应用程序, getpage() 结果被发布到完美停靠/填充的网格中。
Update: Its a desktop application, the getpage() result is posted into a grid which docks/fills perfectly.
(此评论是从另一个帐户写的)
@Anvaka:我所说的完全正确的意思是文档应该“停靠在容器中”,即字体应该调整大小,它应该填充容器的高度和宽度。现在我想起来了,这对于流程文档来说似乎不是一个正确的行为。
当我将流文档放入容器中时,它位于父容器的中间(到目前为止一切顺利)。但父容器没有填充其父容器,因此当我缩放或更改字体大小时,我希望 documentPageView 容器的宽度和高度增加,但保持居中。
(this comment is written from another account)
@Anvaka: What i mean by perfectly right is that the document should "dock in container" that is the fonts should resize, it should fill the container in height and width. Now that im thinking about it, that may not seem like a proper behaviour for a flowdocument.
When i put the flow document in the container it is centered in middle of parent container (so far so good). but the parent container is not filling out its parent container so when i zoom or change font size, i would like the documentPageView container to grow in width and height, but remain centered.