代码:
<Grid>
<telerik:RadGridView x:Name="HierarchialGridView" AutoGenerateColumns="False">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Id}" Header="Id" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
双击单元格后,现在显示默认的白色。 如何在XAML代码中双击单元格时更改单元格的背景颜色?
答案 0 :(得分:1)
如果您想在xaml中执行此操作,我认为您至少需要重新模板化网格或单元格。
但如果你对一点代码隐藏感到满意:
MouseDoubleClick
事件然后:
private void RadGridView_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
FrameworkElement originalSender = e.OriginalSource as FrameworkElement;
if (originalSender != null)
{
var cell = originalSender.ParentOfType<GridViewCell>();
if (cell != null)
{
cell.Background = new SolidColorBrush(Colors.Red);
}
}
}
修改强>
订阅PreparedCellForEdit
活动并:
private void RadGridView_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
var editingControl = e.EditingElement as Control;
if(editingControl !=null)
editingControl.Background = new SolidColorBrush(Colors.Red);
}