![](/img/trans.png)
[英]In a WPF, how do you scroll to the bottom of a FlowDocumentScrollViewer?
[英]How to get TextBlock to Wrap or scroll inside FlowDocumentScrollViewer
我在 4 行 x 2 列网格中有以下 XAML。 Grid.ColumnDefinitions 将两个 ColumnDefinition Width 设置为 *。
<FlowDocumentScrollViewer Style="{StaticResource myFlowDoc}"
Grid.Row="4"
Grid.Column="1" >
<FlowDocument >
<Paragraph LineHeight="12" >
<ItemsControl ItemsSource="{Binding ReceivedData, Mode=OneWay}" />
<TextBlock TextWrapping="Wrap" Text="{Binding /, Mode=OneWay}" />
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
数据来自 ObservaleCollection<string> 并且看起来不错并且可以正确垂直滚动。 但是,当 TextBlock 中的一项不适合水平放置时,文本块将不会换行并且 FlowDocumentScrollViewer 不会显示滚动条。 查看文本的唯一方法是水平扩展窗口。 有谁知道我做错了什么以及为什么 TextWrapping 设置不受欢迎?
如果这里重要的是样式 myFlowDoc
<Style x:Key="myFlowDoc">
<Setter Property="Control.Padding"
Value="0" />
<Setter Property="FlowDocumentScrollViewer.IsToolBarVisible"
Value="True" />
<Setter Property="Control.MinHeight"
Value="150" />
<Setter Property="Control.BorderBrush"
Value="SteelBlue" />
<Setter Property="Control.BorderThickness"
Value="2" />
<Setter Property="Control.VerticalAlignment"
Value="Stretch" />
</Style>
[编辑 1] 这是全屏显示一条错误消息,应该换行。 在此图像下方,我有一个仅显示消息详细信息区域,窗口更宽,因此您可以看到整个消息。 我还将用户控件的整个 xaml 放在https://gist.github.com/1036178#
[编辑 2.1] @Navid 的建议让我间接得到了答案。 删除“/”并将内容包装在数据模板中似乎可以解决问题。 这是新的 XAML
<DataTemplate x:Key="StringCollection">
<TextBlock TextWrapping="Wrap" Text="{Binding}" TextAlignment="Left"/>
</DataTemplate>
<!--... now down in the ItemsControl-->
<ItemsControl ItemsSource="{Binding ReceivedData, Mode=OneWay}"
ItemTemplate="{StaticResource StringCollection}" />
用这个
<ItemsControl ItemsSource="{Binding ReceivedData, Mode=OneWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding /, Mode=OneWay}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
您可以通过使用ListView
作为
<Section Name="Gallery">
<Paragraph>
<ListView ItemsSource="{Binding GalleryCards}"
BorderBrush="Transparent"
HorizontalAlignment="Center"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Padding="10"
Width="{Binding ElementName=Viewer, Path=RenderSize.Width, Converter={StaticResource DocumentSizeConverter}, ConverterParameter=80, UpdateSourceTrigger=PropertyChanged}">
<ListView.ItemTemplate>
<DataTemplate>
<ContentControl s:View.Model="{Binding .}"/>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel HorizontalAlignment="Center" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Paragraph>
</Section>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.