Search code examples
wpfxamldata-bindingwpfdatagridrowdetailstemplate

Can I databind to DataGridRow.DetailsVisibility?


I have a WPF datagrid control with a RowDetailsTemplate. I would like to be able to set a property on an object bound to the row to set whether that particular row should display details.

So for example if I have a basic layout like below and the "Detail" object had a boolean property called "Expanded" is there somewhere I can bind that property to have the details for its row show or not when the value changes?

<DataGrid ItemsSource="{Binding CollectionOfDetailObjects}">
    <DataGrid.Columns>
        <!--My columns here-->
    </DataGrid.Columns>
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <!--Details to show sometimes-->
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>
</DataGrid>

Solution

  • You can bind the DetailsVisibility in the DataGrid.RowStyle.