WPF:ScrollViewer 总内容高度

WPF: ScrollViewer total content height

我正在开发 WPF 应用程序。这是我的界面:

<ScrollViewer x:Name="ScrollView" CanContentScroll="True">
      <RichTextBox Padding="10" x:Name="TextArea" Background="Transparent" Opacity="0.95" />    
</ScrollViewer>

我想将一个文本文件加载到 RichTextBox 中,该文本文件大于屏幕大小,然后找出滚动查看器内容的总大小(即我实际可以滚动多远)。在文档中它说:

ScrollViewer.ExtentHeight Property

A Double that represents the vertical size of the extent. The default is 0.0.

If CanContentScroll is true, the values of the ExtentHeight, ScrollableHeight, ViewportHeight, and VerticalOffset properties are number of items. If CanContentScroll is false, the values of these properties are Device Independent Pixels.

如果理解正确,文档说 ExtentHeight 应该以内容大小为单位给出内容的高度,如果 CanContentScrolltrue。我的 RichTextBox 是滚动视图的内容。因此,如果我的 RichTextBox 长 1000 像素,并且在屏幕上可见 500 像素,则 ExtentHeight 应该为 2。但是,当我加载一个完全适合 [=16] 的空 RichEditBox 时=] 没有滚动,ActualHeight 等于 567,ExtentHeight 等于 37.96,这对我来说毫无意义。我希望它等于 1 或小于 1。那么如何找到 ScrollViewer 中 TextBox 的总内容大小。

我认为我的问题的原因是我在 ScrollViewer 中有我的 RichTextBox。 RichTextBox 有它自己的滚动功能,并且通过将它粘贴到 ScrollViwer 中,它会混淆。所以我摆脱了 ScrollViewver 并仅使用 RichTextBox 及其 HeightExtent 属性.