Change mouseover row color

I was able to apply a column header style with MouseOver VisualState to change the column header color on MouseOver , but unable to do the same for changing a row's mouseover color.  My attempt resulted in rows being solid color rectangles displaying no data and no MouseOver behavior.

Would you have a style snippet for changing a row's MouseOver color?

Thanks,
Alan

1 Reply

SV Srinivasan Vasu Syncfusion Team November 17, 2016 01:58 PM UTC

Hi Alan, 
 
Thanks for contacting Syncfusion support. 
 
You can achieve your requirement by overriding VirtualizingCellsControl. Please refer the below code example. 
 
Code Example 
 
  public class RowStyles : VirtualizingCellsControl 
    { 
        public StyleViruatl() :base() 
        { 
 
        } 
        protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e) 
        { 
            
           if (!String.IsNullOrEmpty((this.DataContext as MyClass).Column1.ToString())) 
           { 
               this.RowHoverBackgroundBrush = new SolidColorBrush(Colors.Red); 
           } 
           else 
           { 
               this.RowHoverBackgroundBrush = new SolidColorBrush(Colors.White); 
           } 
            base.OnMouseEnter(e); 
        } 
 
        protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e) 
        { 
 
            this.RowHoverBackgroundBrush = new SolidColorBrush(Colors.White); 
            base.OnMouseLeave(e); 
 
        } 
    } 
 
    public class CustomRowGenerator : RowGenerator 
    { 
        public CustomRowGenerator(SfDataGrid dataGrid) 
            : base(dataGrid) 
        { 
        } 
        protected override VirtualizingCellsControl GetVirtualizingCellsControl<T>() 
        { 
            //Set the customized VirtualizingCellsControl 
            if (typeof(T) == typeof(VirtualizingCellsControl)) 
                return new RowStyles(); 
            return base.GetVirtualizingCellsControl<T>(); 
        } 
    } 
 
 
 
Regards, 
Srinivasan 
 


Loader.
Up arrow icon