为什么我不能让我的文本块换行

时间:2014-07-10 13:47:08

标签: wpf xaml textwrapping

<ItemsControl ItemsSource="{Binding NavModel.NavCommands, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Grid.Column="0" Grid.Row="1" 
              ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Stretch">
  <ItemsControl.ItemTemplate>
       <DataTemplate>
           <TextBlock Height="20" Margin="10,10,0,0" TextWrapping="Wrap">
               <Hyperlink Command="{Binding Command}">
                    <Run Text="really really raelly long string"></Run>
               </Hyperlink>
            </TextBlock>
       </DataTemplate>
   </ItemsControl>

网格的宽度和高度由各种*值定义。

             <Grid.ColumnDefinitions>
                <ColumnDefinition Width="12*"/>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="77*"/>
                <ColumnDefinition Width="3*"/>
                <ColumnDefinition Width="5*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="92*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="6*"/>
            </Grid.RowDefinitions>

我试过这个没有ScrollViewer.Horizo​​ntalScrollBarVisibility =“已禁用”Horizo​​ntalContentAlignment =“Stretch”。

我如何达到理想的效果?

2 个答案:

答案 0 :(得分:4)

我觉得有点愚蠢。解决方案是删除文本块上的Height属性:(

<TextBlock Height="20" Margin="10,10,0,0" TextWrapping="Wrap">

应该只是

<TextBlock Margin="10,10,0,0" TextWrapping="Wrap">

它有效。

答案 1 :(得分:0)

<TextBlock>
    <Hyperlink NavigateUri="http://www.microsoft.com" RequestNavigate="Hyperlink_RequestNavigate">
        <TextBlock TextWrapping="Wrap">
            Navigate To Microsoft Navigate To Microsoft Navigate To MicrosoftNavigate To MicrosoftNavigate To Microsoft
        </TextBlock>
    </Hyperlink>
</TextBlock>