我有一個FlowDocument,我想填充我的窗口的整個寬度和高度。我曾嘗試使用FlowDocumentPageViewer
(不幸),現在正在使用DocumentPageView
。我仍然無法讓它停靠/填滿整個空間;它只是坐在中間,在最小尺寸就可以創建(是否有意義?)Flowdocument沒有使用全寬/高
這裏是我的代碼:
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>
如果我調整字體的內容僅在垂直方向調整(請注意,拉伸方向設定爲兩個)。有任何想法嗎?
使用預置做到這一點[這裏](http://stackoverflow.com/a/11584307/61577) – cleftheris 2012-07-20 17:41:08