Conditional Styling

This topic will demonstrate how the cells of RadVirtualGrid can be styled conditionally.

This is achieved through the usage of the following two events in conjunction.

  • OverlayBrushesNeeded: The event arguments expose a Brushes collection which can be populated with the Brushes that will be conditionally applied further. When they are preliminarily known, the respective Geometry can be easily drawn at once, instead of applying a style for each cell individually. Thus, the rendering performance of the control is kept unaffected.

Example 1: Adding Brushes through the OverlayBrushesNeeded event

private void VirtualGrid_OverlayBrushesNeeded(object sender,  
        Telerik.Windows.Controls.VirtualGrid.OverlayBrushesEventArgs e) 
  • CellDecorationsNeeded: This is the event through which the actual styling of the cells can be applied. The event arguments expose the following properties:

    • Background: Its value must be set to be one of the Brushes provided by the Brushesh collection populated through the OverlayBrushesNeeded event.
    • ColumnIndex: The column the given cell corresponds to.
    • RowIndex: The row the given cell corresponds to.
    • FontFamily: Sets the FontFamily of the cell.
    • FontSize: Sets the FontSize of the cell.
    • Foreground: Sets the Brush for the Foreground of the cell.

Applying conditional styling through the CellDecorationsNeeded event

private void VirtualGrid_CellDecorationsNeeded(object sender,  
        Telerik.Windows.Controls.VirtualGrid.CellDecorationEventArgs e) 
        if (e.ColumnIndex % 2 == 0) 
            e.Background = Brushes.Red; 
            e.Background = Brushes.Yellow; 
            e.Foreground = Brushes.Red; 
            e.FontSize = 18; 

Figure 1: RadVirtualGrid with conditional styling applied

RadVirtualGrid with conditional styling applied

See also

In this article
Not finding the help you need? Improve this article