1

在银光 2.0 中。我有一些内容要垂直滚动并水平换行。在控件中,我有一个停靠面板。填充它的 DockPanel 的最后一个子项是 ScrollViewer

<UserControl x:Class="MyProject.MyControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:WinControls="clr-namespace:Microsoft.Windows.Controls;
      assembly=Microsoft.Windows.Controls" 
    Width="400" Height="300">
    <WinControls:DockPanel LastChildFill="True">
    ...
<ScrollViewer x:Name="MessageScroll" HorizontalScrollBarVisibility="Hidden"
     VerticalScrollBarVisibility="Auto" BorderThickness="0" >
    <Controls:TextDisplay x:Name="TextDisplay"></Controls:TextDisplay>
</ScrollViewer>

TextDisplay 控件 XAML 如下所示:

<UserControl x:Class="MyProject.TextDisplay"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <TextBlock x:Name="TextDisplayText" TextWrapping="Wrap">
        </TextBlock>
</UserControl>

我想要发生的事情: TextDisplay 应该占据控件的主要区域,如果高度不合适,则使用垂直滚动条。消息在水平方向过长时应该换行。

滚动有效,但现在消息不会在右侧边缘换行。他们只是切断了。它不限制宽度,只是隐藏 Horizo​​ntalScrollBar。如果我设置 Horizo​​ntalScrollBarVisibility="Auto" 我可以看到它们向右滚动。我如何强制它包装?

4

1 回答 1

4

尝试将 ScrollViewer 的 Horizo​​ntalScrollBarVisibility 设置为 Disabled(或不指定值,因为 Disabled 是默认值),然后 TextDisplay 将正确换行并且不会显示水平滚动条。

于 2008-12-01T13:03:06.150 回答