Windows 通用应用程序列表框不显示列表项

Windows Universal app ListBox not showing list items

我有一个列表框,我想将对象列表绑定到该列表框以显示一些信息。每个列表项都包含一个 DocumentMatchCount 对象的对象,其结构如下 -

Public class DocumentMatchCount
{
    public DocumentInfo documentInfo;
    public string count;
}

DocumentInfo class 具有不同的属性,如文件名和路径等。列表框中的每个项目都会显示文件名、路径和计数,即给定输入字符串(用户正在搜索的次数) ) 出现在文档中。

XAML代码:

<ListView x:Name="lvSearchResultDocuments"
          Tapped="lvSearchResultDocuments_Tapped"
          DataContext="DocumentMatchCount">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <RelativePanel>
                    <TextBlock x:Name="txtFileName"
                               Text="{Binding documentInfo.Filename}"></TextBlock>
                    <TextBlock x:Name="txtMatchCount"
                               Text="{Binding count}"
                               FontSize="14"
                               RelativePanel.RightOf="{Binding ElementName=txtFileName}"></TextBlock>
                    <TextBlock Text="{Binding DocumentInfo.Path}"
                               RelativePanel.Below="{Binding ElementName=txtFileName}"
                               TextTrimming="WordEllipsis"></TextBlock>
                </RelativePanel>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Name"
                    Value="{Binding documentInfo.Id}"></Setter>
        </Style>
    </ListView.ItemContainerStyle>
</ListView>

问题是列表项似乎在列表中,但它们不可见。此外,如果我单击任何项​​目,它的单击事件代码将得到完美执行。但只是列表项不可见。

我知道这一定是一个简单的修复,但我对这个桌面应用程序开发还很陌生,所以不会弄错这里。

非常感谢任何帮助。谢谢!

好的,我知道问题出在哪里了。我没有在 DocumentMatchCount class 中设置属性。我声明了这些并使用了 for 绑定,现在它的显示正确了。

感谢 Mohit 的帮助!!