Я хочу использовать dataTemplale внутри dataTemplate.
Я хочу отобразить данные в поле со списком так:
<RoomName>
<Kid Name>
<Kid Name>
<RoomName>
<Kid Name>
<RoomName>
<Kid Name>
<Kid Name>
<Kid Name>
Это то, что я получил. Это не работает.
class Room
{
ObservableCollection<kid> Kids = new Ob...
}
class School
{
ObservableCollection<Room> Rooms = new Ob...
}
class kid
{
Name;
Size;
(...)
}
Это моя привязка из кода:
School BigSchool = new School();
MainListBox.DataContext = BigSchool;
Это мое окно XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Rapideo_Client" mc:Ignorable="d"
x:Class="Rapideo_Client.MainWindow"
Title="Client" SnapsToDevicePixels="True" Height="400" Width="625">
<Window.Resources>
<DataTemplate x:Key="kidTemplate" DataType="Kid">
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold"></TextBlock>
<Label Content="{Binding Path=Size}"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="roomTemplate" DataType="Room">
<StackPanel Orientation="Vertical">
<Label Content="{Binding Path=Kids.Count}"/>
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding Path=Kids}" ItemTemplate="{DynamicResource kidTemplate}" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" x:Name="MainListBox" Grid.Column="1" ItemsSource="{Binding Rooms}" ItemTemplate="{DynamicResource roomTemplate}" />
</Window>