Can’t load subordinated List

I want to create a subordinate list for each school in my list, that shows the school subjects.

  1. I define the data structure of the school and the subjects with these models:
public class SchoolModel
{
    public int SchoolId { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public List<SubjectModel> Subjects { get; set; }
}
public class SubjectModel
{
    public int SubjectId { get; set; }
    public int SchoolId { get; set; }
    public string Name { get; set; }
}
  1. Then I loaded the values for the models from my database and put it in my Schools ObervableCollection in ViewModel.

  2. Then I created a list of the schools in my View Class, which worked well so far. Then I tried to create a subordinate list to load my subjects there

4.The problem is that the subjects are only loaded when I remove the StaticResource from my SchoolListView and then the schools are removed

<Border BorderBrush="black" BorderThickness="0, 0, 1, 1" Grid.Column="0" Grid.RowSpan="2">
    <StackPanel Orientation="Vertical">
        <Border BorderThickness="0, 0, 0, 1" BorderBrush="#202225" Margin="0, 0, 0, 10">
            <TextBlock Text="Schools" HorizontalAlignment="Center" Padding="10" FontSize="25" Foreground="#ffffff"/>
        </Border>

            <ListView Name="SchoolListView" ItemsSource="{Binding Schools}" Background="Transparent" 
                  BorderThickness="0" ItemContainerStyle="{StaticResource SchoolsCard}"
                   SelectionChanged="SchoolListView_SelectionChanged">
                <ListView.ItemTemplate>
                    <DataTemplate>
                    <ListView ItemsSource="{Binding Subjects}" Background="Transparent"
                              BorderThickness="0" ItemContainerStyle="{StaticResource SubjectsCard}">

                    </ListView>
                </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
     </StackPanel>
</Border>

SchoolsCard:

<Style TargetType="ListBoxItem" x:Key="SchoolsCard">

    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="#202225"/>
        </Trigger>
    </Style.Triggers>

    <Setter Property="Background" Value="#36393f"/>

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ListViewItem">
                <Border Background="{TemplateBinding Background}" Height="50" CornerRadius="3" Margin="8, 2, 8, 2" BorderBrush="#202225" BorderThickness="1">

                    <StackPanel Orientation="Horizontal" Margin="10, 0, 0, 0">

                        <StackPanel>
                            <Label Content="{Binding Name}" Foreground="#ffffff"/>
                            <Label Content="{Binding Address}"  Foreground="#b9bbbe" FontSize="10" Margin="0, -5, 0, 0"/>
                        </StackPanel>
                    </StackPanel>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

SubjectsCard:

    <Style TargetType="ListBoxItem" x:Key="SubjectsCard">

        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="#202225"/>
            </Trigger>
        </Style.Triggers>

        <Setter Property="Background" Value="#36393f"/>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListViewItem">
                    <Border Background="{TemplateBinding Background}" Height="30" CornerRadius="3" Margin="8, 2, 8, 2" BorderBrush="#202225" BorderThickness="1">

                        <StackPanel>
                            <Label Content="{Binding Name}" Foreground="#ffffff" FontSize="10" Padding="5" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </StackPanel>

                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

New contributor

susmi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

3

The problem is that the ControlTemplate in the SchoolsCard Style does not contain a ContentPresenter which would show the nested ListView that is declared in the inner ItemTemplate.

As a starting point, you could use only ItemTemplates. The basic structure would be similar to this:

<ListBox ItemsSource="{Binding Schools}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Name}"/>
                <TextBlock Text="{Binding Address}"/>
                <ListBox ItemsSource="{Binding Subjects}" >
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật