我有一个列表框,我想绑定一个对象列表来显示一些信息。每个列表项都包含DocumentMatchCount对象的对象,该对象具有如下结构 -
Public class DocumentMatchCount
{
public DocumentInfo documentInfo;
public string count;
}
DocumentInfo类具有不同的属性,如文件名和路径等。列表框中的每个项目都将显示文件名,其路径和计数,该计数是给定输入字符串(用户正在搜索的)在文档中出现的次数。
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>
问题是列表项似乎在列表中,但它们不可见。此外,如果我点击任何项目,它的点击事件代码将完美执行。但只是列表项不可见。
我知道这一定是一个简单的修复,但我对这个桌面应用程序的开发还很陌生,所以不要错过这里。
非常感谢任何帮助。谢谢!
答案 0 :(得分:0)
好的,我弄清楚问题是什么。我没有在DocumentMatchCount类中设置属性。我声明了那些,并使用了绑定,现在它正确显示。
感谢Mohit的帮助!!