【发布时间】:2015-04-17 08:11:20
【问题描述】:
我不确定为什么我的代码没有正确执行 TextWrapping。它不包装描述列的文本(这是我想要的)。它只是将其切断,甚至不使用“...”让我知道还有更多数据。
我尝试使用我在网上找到的这段代码来完成这项工作,但它不起作用。理想情况下,我希望能够只将 TextWrap 设置为某些列,而不是一般地跨所有 DataGridCell 对象。
哦,请注意我使用的是 Microsoft.NET 4,所以这是通过它提供的 DataGrid,而不是来自 WPF 工具包。
<DataGrid Name="TestGrid" Grid.Row="2" Grid.ColumnSpan="2" AutoGenerateColumns="False" ItemsSource="{Binding IntTypes}" SelectedValue="{Binding CurrentIntType}">
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Name="DataGridCellBorder">
<TextBlock Background="Transparent" TextWrapping="WrapWithOverflow" TextTrimming="CharacterEllipsis" Height="auto" Width="auto">
<ContentPresenter Content="{TemplateBinding Property=ContentControl.Content}" ContentTemplate="{TemplateBinding Property=ContentControl.Content}" />
</TextBlock>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding ID}" IsReadOnly="True" />
<DataGridTextColumn Header="Interested Parties Description" Binding="{Binding Description}" IsReadOnly="False" />
</DataGrid.Columns>
</DataGrid>
提前致谢!
【问题讨论】: