New to Telerik UI for WPF? Download free 30-day trial

Row Details Events

RadGridView control exposes several events regarding the RowDetails:

More about the events that the RadGridView exposes, can be found here.

  • LoadingRowDetails: The event is raised immediately after the FrameworkElement has been loaded from the Row Details DataTemplate. It is raised the very first time the row details are about to be shown. Once this event has been fired, it will never fire again for that row. However, if the row is recycled and then realized, it starts its "life" again, this event will be fired again the first time the details are about to be shown.

Setting the Background of the DetailsPresenter

The GridViewRowDetailsEventArgs provide access to the FrameworkElement that has been just loaded (DetailsElement) as well as to the respective GridViewRow(Row). Use this event if you want to modify the FrameworkElement in any way before it is displayed.

For example, if you have a RadGridView with the following RowDetailsTemplate:

Example 1: Defining the RowDetailsTemplate

<telerik:RadGridView x:Name="radGridView" 
                LoadingRowDetails="radGridView_LoadingRowDetails"> 
    <telerik:RadGridView.RowDetailsTemplate> 
        <DataTemplate> 
            <StackPanel Orientation="Horizontal"> 
                <TextBlock Text="City: " /> 
                <TextBlock Text="{Binding City}" /> 
            </StackPanel> 
        </DataTemplate> 
    </telerik:RadGridView.RowDetailsTemplate> 
    <!--...--> 
</telerik:RadGridView> 

You can change the StackPanel's Background depending on is the row alternating:

Example 2: Setting the Background of the DetailsElement

private void radGridView_LoadingRowDetails(object sender, GridViewRowDetailsEventArgs e) 
{ 
    StackPanel element = e.DetailsElement as StackPanel; 
    if (e.Row.IsAlternating) 
    { 
        element.Background = new SolidColorBrush(Colors.Black); 
    } 
    else 
    { 
        element.Background = new SolidColorBrush(Colors.White); 
    } 
} 
Private Sub radGridView_LoadingRowDetails(ByVal sender As Object, ByVal e As GridViewRowDetailsEventArgs) 
    Dim element As StackPanel = TryCast(e.DetailsElement, StackPanel) 
 
    If e.Row.IsAlternating Then 
        element.Background = New SolidColorBrush(Colors.Black) 
    Else 
        element.Background = New SolidColorBrush(Colors.White) 
    End If 
End Sub 

Accessing the Expanded Item

The event arguments expose the Row property through which the parent item of the details can be fetched.

Example 3: Accessing the expanded item

private void clubsGrid_LoadingRowDetails(object sender,  
        Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e) 
    { 
        var club = e.Row.DataContext as Club; 
    } 
Private Sub clubsGrid_LoadingRowDetails(ByVal sender As Object,  
        ByVal e As Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs) 
        Dim club = TryCast(e.Row.DataContext, Club) 
End Sub  
  • UnloadingRowDetails: When the Row Details DataTemplate is modified or deleted, the UnloadingRowDetails event is raised in case you need to perform some cleanup for the old template before the new one is loaded.

  • RowDetailsVisiblityChanged: This event is fired each time the row details are shown or hidden, i.e. by selecting or deselecting the row. Via the GridViewRowDetailsEventArgs you could access the just loaded DetailsElement, the respective GridViewRow (Row) as well as the Visibility of the row details.

To manually change the visibility of a row - set its DetailsVisibility property to either Visibility.Collapsed or Visibility.Visible

See Also

In this article