所以我有这种情况:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Margin="0,0,5,0">
<Image Source="{Binding ClubController.Club.Stadium.Image}" />
</Grid>
<UniformGrid Rows="13" HorizontalAlignment="Left" Grid.Column="1">
<TextBlock Text="Address:" FontWeight="Bold"/>
<TextBlock Text="Telephone:" FontWeight="Bold"/>
</UniformGrid>
<UniformGrid Rows="13" HorizontalAlignment="Center" Grid.Column="2">
<TextBlock Text="{Binding ClubController.Club.Stadium.Address}" />
<TextBlock Text="{Binding ClubController.Club.Stadium.Telephone}" />
</UniformGrid>
</Grid>
你可以看到我设计了一个有三列的网格,所以最终的结果就是:
[image][default text][binded text]
问题是文本块上的某些绑定文本属性太长,所以当用户调整窗口大小时,我会得到文本切割。我希望在调整窗口大小并剪切文本时显示类似滚动条的内容,以便用户可以移动滚动条并查看完整文本。我怎样才能做到这一点?感谢。
答案 0 :(得分:0)
试试这个:
<UniformGrid Rows="13" HorizontalAlignment="Left" Grid.Column="1">
<TextBlock Text="Address:" FontWeight="Bold" />
<TextBlock Text="Telephone:" FontWeight="Bold" />
</UniformGrid>
<UniformGrid Rows="13" HorizontalAlignment="Center" Grid.Column="2">
<TextBlock Text="{Binding ClubController.Club.Stadium.Address}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto" />
<TextBlock Text="{Binding ClubController.Club.Stadium.Telephone}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto" />
</UniformGrid>
编辑,为文本块添加样式(我没有检查它是否有效)
<Style x:Key="TextBlockWithScroll" TargetType="{x:Type TextBlock}">
<Setter Property="ScrollViewer.CanContentScroll" Value="True" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
</Style>
现在您的文本块使用样式
<TextBlock Text="{Binding ClubController.Club.Stadium.Address}" Style="{DynamicResource TextBlockWithScroll}" />