FlowDocumentScrollViewer 不会滚动
我正在尝试找到最可扩展的方式来在窗口内显示 FlowDocument
- 只是一个 FlowDocument
。我有:
<FlowDocumentScrollViewer x:Name="message" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible">
然后在窗口的构造函数中,我将查看器的文档设置为从 XAML 加载的文档(在代码中)。 XAML 包含:
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="{x:Null}"
FontSize="12" FontFamily="Segoe UI" PagePadding="2">
<BlockUIContainer>
<BlockUIContainer.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</BlockUIContainer.Resources>
<StackPanel MaxWidth="200">
<TextBlock Text="{Binding DefinedWord}" FontWeight="Bold" />
<ListBox ItemsSource="{Binding Definitions}"
Style="{StaticResource InvisibleListBox}" Margin="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.CanContentScroll="false">
...
无论我尝试什么,FlowDocumentScrollViewer
都不会滚动,并且我看不到文档的截断部分。它与 BlockUIContainer
有什么关系,还是我错过了其他东西?
I'm trying to find the most expandable way to show a FlowDocument
inside a window - just a FlowDocument
. I have:
<FlowDocumentScrollViewer x:Name="message" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible">
Then in the constructor for the Window, I set the Document of the viewer to one I load from XAML (in code). The XAML contains:
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="{x:Null}"
FontSize="12" FontFamily="Segoe UI" PagePadding="2">
<BlockUIContainer>
<BlockUIContainer.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>
</BlockUIContainer.Resources>
<StackPanel MaxWidth="200">
<TextBlock Text="{Binding DefinedWord}" FontWeight="Bold" />
<ListBox ItemsSource="{Binding Definitions}"
Style="{StaticResource InvisibleListBox}" Margin="0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.CanContentScroll="false">
...
No matter what I try, the FlowDocumentScrollViewer
does not scroll and I can't see the truncated parts of the document. Does it have anything to do with the BlockUIContainer
, or am I missing something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终通过将文档内的
ListBox
设置为IsHitTestVisible="false"
来实现此工作,然后绑定文本块内的Width
将ListBoxItem
模板设置为ListBoxItem
的ActualWidth
。I eventually got this working by setting the
ListBox
inside the document toIsHitTestVisible="false"
, then binding theWidth
of a text block inside theListBoxItem
template to theActualWidth
of theListBoxItem
.使用流程文档灵活显示内容
Flexible Content Display With Flow Documents
对我来说,
FlowDocumentScrollViewer
的替代选项有效,请参阅以下示例:
http://msdn.microsoft.com/en-us /library/system.windows.controls.richtextbox.aspx
其他选项可能是
FlowDocumentPageViewer
、FlowDocumentReader
。For me alternate option to
FlowDocumentScrollViewer
worked,See the example in,
http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx
The other options may be
FlowDocumentPageViewer
,FlowDocumentReader
.