我正在使用 WPF DataGrid,其中如果该行可编辑,其中一列需要显示“编辑”超链接 - 这由该行的支持模型中的布尔标志指示。我能够使用 DataGridTemplateColumn 实现这一点 - 没有问题。然而,对整行的附加要求是在选择该行时不显示任何突出显示(默认情况下为蓝色背景)。我已经能够通过定义具有透明背景的 DataGridCell 样式在其他列上实现此目的,例如
<DataGridTextColumn
Header="Id"
Binding="{Binding Path=Id}"
HeaderStyle="{StaticResource DataGridColumnHeaderStyle}"
CellStyle="{StaticResource DataGridCellStyle}" />
其中 DataGridCellStyle 定义如下:
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent" />
...
</Style>
但是,有问题的列(DataGridTemplateColumn)不提供“CellStyle”属性,我可以使用该属性来关闭选择突出显示。所以我的问题是使用 DataGridTemplateColumn 时如何设置单元格样式?这是我对满足第一个要求的列的实现(即,如果该行可编辑,则显示“编辑”超链接):
<DataGridTemplateColumn
Header="Actions"
HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock
Visibility="{Binding Path=Editable, Converter={StaticResource convVisibility}}"
Style="{StaticResource CenterAlignedElementStyle}">
<Hyperlink
Command="..."
CommandParameter="{Binding}">
<TextBlock Text="Edit" />
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Thanks.
至少在WPF4中,有一个DataGridTemplateColumns的CellStyle:http://msdn.microsoft.com/en-us/library/cc189163.aspx http://msdn.microsoft.com/en-us/library/cc189163.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)