目前我的网格正在更改为自动生成列,因此我无法预定义列样式。我想知道如何基于标头值为列设置样式触发器。
使用AutoGenerateColumns="True"
<telerik:GridViewColumn Header="Test">
<telerik:GridViewColumn.CellEditTemplate>
<DataTemplate x:Key="ToggleDataTemplate">
<telerik:RadToggleButton Content="+" Width="20" Height="20"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
</DataTemplate>
</telerik:GridViewColumn.CellEditTemplate>
</telerik:GridViewColumn>
我使用AutoGenerateColumns="False"
<telerik:RadGridView.Resources>
<Style TargetType="telerik:GridViewColumn">
<Style.Triggers>
<Trigger Property="Header" Value="Test">
<Setter Property="CellTemplate" Value="{StaticResource ToggleDataTemplate}" />
<Setter Property="CellEditTemplate" Value="{StaticResource ToggleDataTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
</telerik:RadGridView.Resources>
<DataTemplate x:Key="ToggleDataTemplate">
<telerik:RadToggleButton Content="+" Width="20" Height="20"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
</DataTemplate>
根据我上面的尝试,细胞仍然是空白的。如何让按钮动态显示?
答案 0 :(得分:0)
您应该能够处理AutoGeneratingColumn
事件并以编程方式设置所有列的CellEditTemplate
:
<telerik:RadGridView x:Name="grid" AutoGeneratingColumn="grid_AutoGeneratingColumn">
<telerik:RadGridView.Resources>
<DataTemplate x:Key="ToggleDataTemplate">
<telerik:RadToggleButton Content="+" Width="20" Height="20"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"/>
</DataTemplate>
</telerik:RadGridView.Resources>
</telerik:RadGridView>
private void grid_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
e.Column.CellEditTemplate = grid.Resources["ToggleDataTemplate"] as DataTemplate;
}