DataGrid.RowDetailsTemplate Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the template that is used to display the row details.
public:
property System::Windows::DataTemplate ^ RowDetailsTemplate { System::Windows::DataTemplate ^ get(); void set(System::Windows::DataTemplate ^ value); };
public System.Windows.DataTemplate RowDetailsTemplate { get; set; }
member this.RowDetailsTemplate : System.Windows.DataTemplate with get, set
Public Property RowDetailsTemplate As DataTemplate
Property Value
The template that is used to display the row details. The registered default is null
. For more information about what can influence the value, see DependencyProperty.
Examples
The following example shows a DataGrid with a RowDetailsTemplate defined inline. The DataGrid displays three values in each row and three more values in the details section when the row is selected. This example is part of a larger example available in the How to: Add Row Details to a DataGrid Control topic.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
Loaded="Window_Loaded">
<Grid>
<DataGrid Name="dataGrid1" IsReadOnly="True" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Company Name" Binding="{Binding CompanyName}"></DataGridTextColumn>
<DataGridTextColumn Header="Contact First Name" Binding="{Binding FirstName}"></DataGridTextColumn>
<DataGridTextColumn Header="Contact Last Name" Binding="{Binding LastName}"></DataGridTextColumn>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<Border BorderThickness="0" Background="BlanchedAlmond" Padding="10">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="12" Text="Email: " VerticalAlignment="Center" />
<TextBlock FontSize="16" Foreground="MidnightBlue" Text="{Binding EmailAddress}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="12" Text="Phone: " VerticalAlignment="Center" />
<TextBlock FontSize="16" Foreground="MidnightBlue" Text="{Binding Phone}" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock FontSize="12" Text="Sales Person: " VerticalAlignment="Center" />
<TextBlock FontSize="16" Foreground="MidnightBlue" Text="{Binding SalesPerson}" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
</Grid>
</Window>
Remarks
You can customize the data presentation in the DataGrid by adding a row details section. Adding a row details section enables you to group some data in a template that is optionally visible or collapsed.
You define the row details template as either inline XAML or as a resource. A data template that is added as a resource can be used throughout the project without re-creating the template. A data template that is added as inline XAML is only accessible from the control where it is defined.
You can modify the RowDetailsTemplate before it is displayed by handling the LoadingRowDetails event. You should handle the UnloadingRowDetails event to undo changes that are made while loading the row details.