Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's say that you have following classes:</p> <pre><code>class InvoiceItem { public string ItemName { get; set; } public List&lt;InvoiceOption&gt; Options { get; set; } } class InvoiceOption { public string OptionName { get; set; } } </code></pre> <p>ListView solution:</p> <pre><code>&lt;ListView x:Name="temsReceipt" ItemsSource="{Binding}"&gt; &lt;ListView.Resources&gt; &lt;Style TargetType="ListViewItem"&gt; &lt;Setter Property="HorizontalContentAlignment" Value="Stretch" /&gt; &lt;/Style&gt; &lt;/ListView.Resources&gt; &lt;ListView.View&gt; &lt;GridView&gt; &lt;GridViewColumn&gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Height="40" Width="50"&gt;&lt;/TextBlock&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Header="Item Name" Width="230" &gt; &lt;GridViewColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;Grid HorizontalAlignment="Stretch"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="40" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;TextBlock Text="{Binding ItemName}" VerticalAlignment="Center" FontWeight="Bold" FontSize="18"/&gt; &lt;ListBox ItemsSource="{Binding Options}" Grid.Row="1" Background="Yellow" HorizontalAlignment="Stretch"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding OptionName}" /&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/GridViewColumn.CellTemplate&gt; &lt;/GridViewColumn&gt; &lt;GridViewColumn Header="Item Price" Width="100" DisplayMemberBinding="{Binding ItemPrice}"/&gt; &lt;/GridView&gt; &lt;/ListView.View&gt; &lt;/ListView&gt; </code></pre> <p>If you want to use DataGrid you can use RowDetailsTemplate:</p> <pre><code>&lt;DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="Name" Binding="{Binding ItemName}" /&gt; &lt;/DataGrid.Columns&gt; &lt;DataGrid.RowDetailsTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Margin="2" Background="Yellow"&gt; &lt;TextBlock Text="Options:" /&gt; &lt;ListBox ItemsSource="{Binding Options}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{Binding OptionName}" /&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/DataGrid.RowDetailsTemplate&gt; &lt;/DataGrid&gt; </code></pre> <p>Sample data:</p> <pre><code>... public MainWindow() { InitializeComponent(); List&lt;InvoiceItem&gt; _source = new List&lt;InvoiceItem&gt; { new InvoiceItem { ItemName = "Item1", Options = new List&lt;InvoiceOption&gt; { new InvoiceOption { OptionName = "Option1" }, new InvoiceOption { OptionName = "Option2" } } }, new InvoiceItem { ItemName = "Item2", Options = new List&lt;InvoiceOption&gt; { new InvoiceOption { OptionName = "Option3" }, new InvoiceOption { OptionName = "Option4" } } } }; this.DataContext = _source; } ... </code></pre> <p>ListView result:</p> <p><img src="https://i.stack.imgur.com/GaGRQ.png" alt="enter image description here"></p>
 

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