문제

Code:

<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>

Now default white color is displaying after double clicking a cell. How to achieve to change the background color of a cell when it is double clicked in XAML code ?

도움이 되었습니까?

해결책

If you want to do it in xaml I think that you need at least to re-template the grid or the cell.

But if you are ok with a little code-behind:

  • Add and handler for the MouseDoubleClick event for the RadGrid

and then:

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);
          }
     }
}

Edit:

Subscribe to the PreparedCellForEdit event and:

private void RadGridView_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
{
    var editingControl = e.EditingElement as Control;
    if(editingControl !=null)
       editingControl.Background = new SolidColorBrush(Colors.Red);

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top