Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I expand a Datagrid details section from a button click?
    primarykey
    data
    text
    <p>I'm trying to implement a datagrid that works like a folder tree (i.e. each row represents a folder and the details view is another datagrid showing files in the folder). I've tried to trim down my code for simplicity, so there could be mistakes, but here is my basic XAML layout:</p> <pre><code>&lt;my:DataGrid Name="dataGrid1" AutoGenerateColumns="False" ItemsSource="{Binding}"&gt; &lt;my:DataGrid.RowDetailsTemplate&gt; &lt;DataTemplate&gt; &lt;my:DataGrid ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type my:DataGrid}}, Path=SelectedItem.Files}" AutoGenerateColumns="False" HeadersVisibility="None"&gt; &lt;my:DataGrid.Columns&gt; &lt;my:DataGridTextColumn Binding="{Binding Path=FileName}" /&gt; &lt;my:DataGridTextColumn Binding="{Binding Path=FSize}" /&gt; &lt;/my:DataGrid.Columns&gt; &lt;/my:DataGrid&gt; &lt;/DataTemplate&gt; &lt;/my:DataGrid.RowDetailsTemplate&gt; &lt;my:DataGrid.Columns&gt; &lt;my:DataGridTemplateColumn CanUserResize="False" CanUserSort="False" Width="16"&gt; &lt;my:DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Button Click="Button_Click_1"&gt; &lt;Image Source="resources/+.ico" /&gt; &lt;/Button&gt; &lt;/DataTemplate&gt; &lt;/my:DataGridTemplateColumn.CellTemplate&gt; &lt;/my:DataGridTemplateColumn&gt; &lt;my:DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" /&gt; &lt;/my:DataGrid.Columns&gt; &lt;/my:DataGrid&gt; </code></pre> <p>I'm trying to have the button expand the details row, but I'm not sure how to reference the row:</p> <pre><code> private void Button_Click_1(object sender, RoutedEventArgs e) { // how do I reference a row here? DataGridRow row = ? // so I can do this: if (row.DetailsVisibility == Visibility.Collapsed) row.DetailsVisibility = Visibility.Visible; else row.DetailsVisibility = Visibility.Collapsed; } </code></pre> <p>Hopefully the question is clear... Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload