Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf RichTextBox与FlowDocumentScrollViewer-为什么它们看起来如此不同?_Wpf_Richtextbox_Flowdocumentscrollviewer - Fatal编程技术网

Wpf RichTextBox与FlowDocumentScrollViewer-为什么它们看起来如此不同?

Wpf RichTextBox与FlowDocumentScrollViewer-为什么它们看起来如此不同?,wpf,richtextbox,flowdocumentscrollviewer,Wpf,Richtextbox,Flowdocumentscrollviewer,我有一个非常简单的xaml文件,其中我将相同的段落和运行元素传递给RichTextBox和FlowDocumentScrollViewer。两者看起来完全不同——这不是我所期望的 我知道您可以设置FlowDocument或容器的样式,使它们看起来相同,但我希望它们都继承相同的“默认”设置 这是我的密码: <Grid> <Grid.RowDefinitions> <RowDefinition Height="80" />

我有一个非常简单的xaml文件,其中我将相同的段落和运行元素传递给RichTextBox和FlowDocumentScrollViewer。两者看起来完全不同——这不是我所期望的

我知道您可以设置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相同的内容,但我真的不想做这样的事情,因为毫无疑问会出现一些字体或区域设置严重破坏这一切的情况。

我不是WPF方面的专家,特别是因为我确实使用了RichTextBox,但是使用样式(甚至可能是模板)将其中一个的属性绑定到另一个上可能会解决您的问题

FlowDocument的默认属性不同于RTB或TB的属性。(FlowDocument的默认字体为Georgia!!!)


...
...
希望你能用这个

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