Erstens müssen Sie Ihre Sammlung von Item
Objekte in eine geeignete Sammlung:
var dict = data.Select(i => i.UnitId).Distinct()
.ToDictionary(u => u, u => data
.Where(i => i.UnitId == u)
.ToDictionary(d => d.RoomId, d => d));
var rooms = dict.Values.First().Keys;
DataContext = Tuple.Create(dict, rooms);
und dann brauchen Sie eine ItemsControl
mit dem richtigen DataTemplate
Konfiguration
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ItemsControl ItemsSource="{Binding Item2}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"
Margin="80,0,0,0" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock HorizontalAlignment="Center"
Foreground="Blue"
Width="80"
Margin="5">
<Run Text="Room" />
<Run Text="{Binding Mode=OneWay}" />
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl ItemsSource="{Binding Item1}"
AlternationCount="{Binding Count}"
Grid.Row="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center"
Foreground="Blue"
Width="80">
<Run Text="Unit" />
<Run Text="{Binding Key, Mode=OneWay}" />
</TextBlock>
<ItemsControl ItemsSource="{Binding Value}"
VerticalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Value.Cost, StringFormat={}{0:C}}"
Margin="5"
Width="80" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
und dann bekommen Sie das hier: