2

ウィンドウの幅と高さ全体を埋めたい 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このコードには 2 つのメソッドの組み合わせが含まれていますが、現在使用されているのは のみであることに注意してください。これは、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>

フォントのサイズを変更すると、コンテンツは垂直方向にのみサイズ変更されます (ストレッチ方向が両方に設定されていることに注意してください)。何か案は?

4

5 に答える 5

4

私はで同様の問題を抱えていましたFlowDocumentScrollViewが、この解決策は次の場合にも機能するようですFlowDocumentPageView

プロパティがに設定されているため、FlowDocumentは中央に配置されます。この動作を修正するようにPagePaddingを設定します。PagePaddingauto,auto,auto,auto0

<FlowDocumentScrollViewer VerticalScrollBarVisibility="Auto">
    <FlowDocument PagePadding="0">
    </FlowDocument>
</FlowDocumentScrollViewer>
于 2010-09-22T16:08:16.560 に答える
1

次の行により、要素が中央に配置されます(これはストレッチと同じではありません)。

viewer.VerticalAlignment = VerticalAlignment.Center;
viewer.HorizontalAlignment = HorizontalAlignment.Center;
pageView.VerticalAlignment = VerticalAlignment.Center;
pageView.HorizontalAlignment = HorizontalAlignment.Center;

ここでのデフォルトの配置はストレッチであるため、安全に削除できます。

それでもビューアを中央に配置する場合は、ページサイズを明示的に定義します(1インチに96ポイントがあり、マージンとPageSizeはポイントで設定されていることに注意してください)。

幅=96* 8.5

高さ=96* 11

于 2011-08-03T04:43:42.227 に答える
0

GetPage()メソッドの結果をどこでどのように使用するかを指定していただけますか? xbap ですか、それともデスクトップ アプリケーションですか。

次のドキュメントがKaxamlで完全に正しく表示されるため、これを求めています。

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

PS: デスクトップ アプリケーションの場合は、Pete BloisからのSnoop ツールを使用して問題の原因をいつでも特定できます。

于 2009-08-31T20:06:32.600 に答える
-2

更新: デスクトップ アプリケーションです。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>
于 2009-08-31T20:11:57.860 に答える
-2

(このコメントは別のアカウントから書かれています)

@Anvaka: 完全に正しいとは、ドキュメントが「コンテナーにドッキング」する必要があることです。つまり、フォントのサイズを変更し、コンテナーの高さと幅を埋める必要があります。考えてみると、それはフロードキュメントの適切な動作とは思えないかもしれません。

フロー ドキュメントをコンテナーに配置すると、親コンテナーの中央に配置されます (これまでのところ、非常に良い)。しかし、親コンテナは親コンテナを埋めていないので、ズームまたはフォントサイズを変更すると、documentPageView コンテナの幅と高さが大きくなり、中央に配置されたままになります。

于 2009-09-01T06:51:34.610 に答える