Note that there are some explanatory texts on larger screens.

plurals
  1. POManually group DataGrid items
    primarykey
    data
    text
    <p>I need to use a data grid and my data looks as follows: firstName, lastName, street, zip, city, country, image</p> <p>In my datagrid I will only show firstName, lastName and image but it has to be grouped after city. </p> <p><strong>Update</strong> The code below shows grouped items but the three items I want to display (firstName, lastName, image) are followed by all items (firstName, lastName, street, zip, city, country, image) per row. I think I have to replace the <code>&lt;ItemsPresenter /&gt;</code> but thats only speculation..</p> <p>Can anyone help me, I can't manage this on my own...</p> <pre><code>&lt;Grid&gt; &lt;DataGrid ItemsSource="{Binding GroupedMovables}"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTemplateColumn Header="Preview" Width="SizeToCells" IsReadOnly="True"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Image Name="Preview" Height="20" Source="{Binding Image}" HorizontalAlignment="Center" /&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;DataGridTextColumn Header="first name" Binding="{Binding FirstName}" /&gt; &lt;DataGridTextColumn Header="last name" Binding="{Binding LastName}" /&gt; &lt;/DataGrid.Columns&gt; &lt;DataGrid.GroupStyle&gt; &lt;GroupStyle&gt; &lt;GroupStyle.HeaderTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding Path=City}" FontWeight="Bold" Padding="3"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/GroupStyle.HeaderTemplate&gt; &lt;GroupStyle.ContainerStyle&gt; &lt;Style TargetType="{x:Type GroupItem}"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt; &lt;Expander&gt; &lt;Expander.Header&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="{Binding Path=Name}" /&gt; &lt;TextBlock Text="{Binding Path=ItemCount}" Margin="8,0,4,0"/&gt; &lt;TextBlock Text="Element(s)"/&gt; &lt;/StackPanel&gt; &lt;/Expander.Header&gt; &lt;ItemsPresenter /&gt; &lt;/Expander&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/GroupStyle.ContainerStyle&gt; &lt;/GroupStyle&gt; &lt;/DataGrid.GroupStyle&gt; &lt;/DataGrid&gt; &lt;/Grid&gt; </code></pre>
    singulars
    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.
 

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