首页 > 解决方案 > 项目控件绑定不显示任何内容?

问题描述

出于某种原因,我的 XAML 没有为我的项目控件显示任何内容。我使用学生列表作为我的 ItemsSource 并引用该列表的属性来创建自定义控件。

这是我的 XAML:

<ItemsControl ItemsSource="{Binding Class.Students}" Grid.Row="1">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <ComboBox>
                                <ComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="500"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                            <TextBlock Text="{Binding FavoriteSubject, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1"/>

                                        </Grid>
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

现在,下拉菜单是空的。绑定是正确的,如果我将它们拉到 ItemsControl 之外,它们会显示得很好。我缺少关于 ItemsControls 的某些特定内容吗?

标签: wpfxaml

解决方案


推荐阅读