3

同じ Paragraph 要素と Run 要素を RichTextBox と FlowDocumentScrollViewer の両方に渡す非常に単純な xaml ファイルがあります。両方とも根本的に異なって見えます - これは私が期待していたものではありません.

FlowDocument またはコンテナのいずれかをスタイルして同じように見えることは理解していますが、両方が同じ「デフォルト」設定を継承することを期待していました。

これが私のコードです:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="80" />
        <RowDefinition Height="80" />
        <RowDefinition Height="80" />
    </Grid.RowDefinitions>
    <RichTextBox Grid.Row="0">
        <FlowDocument>
            <Paragraph>
                <Run>Here is some text</Run>
                <LineBreak />
                <Run>Here is some more text</Run>
            </Paragraph>
        </FlowDocument>
    </RichTextBox>
    <TextBlock Grid.Row="1" Padding="6,0,0,0">
        <Run>Here is some text</Run>
        <LineBreak />
        <Run>Here is some more text</Run>
    </TextBlock>
    <FlowDocumentScrollViewer Grid.Row="2" IsHitTestVisible="True" VerticalScrollBarVisibility="Hidden">
        <FlowDocument>
            <Paragraph>
                <Run>Here is some text</Run>
                <LineBreak />
                <Run>Here is some more text</Run>
            </Paragraph>
        </FlowDocument>
    </FlowDocumentScrollViewer>
</Grid>

私の質問

RichTextBox と FlowDocumentScrollViewer の両方が同じ方法で FlowDocument を表示するようにする方法はありますか? 理想的には、マージンやフォントなどをどちらかに「ハードコード」する必要なしに、それらの違いを見分けることができないようにすることです。

上記の例で、Textblock を RichTextBlock と同じように表示するにはマージンが必要であることがわかりますが、フォントやカルチャの設定によっては間違いなくこのようなことをする必要はありません。これをすべてひどく壊します。

4

1 に答える 1

3

私は WPF の専門家ではありません。特に RichTextBox を実際に使用しているためですが、いずれかのプロパティをスタイル (おそらくテンプレート化) でバインドすることで問題を解決できる可能性があります。

FlowDocument の既定のプロパティは、RTB や TB のものとは異なります。(FlowDocument のデフォルトのフォントはジョージアです!!!)

    <RichTextBox>
        <FlowDocument Name="rtDoc"
                      PagePadding="{Binding PagePadding, ElementName=flDoc}"
                      ...
                      FontFamily="{Binding FontFamily, ElementName=flDoc}">
            ...
        </FlowDocument>
    </RichTextBox>
        ...
    <FlowDocumentScrollViewer>
        <FlowDocument Name="flDoc" />
    </FlowDocumentScrollViewer>

これを使用できることを願っています!

于 2009-12-08T04:11:33.283 に答える