Reputation: 157
I have a listbox to which I want to bind a list of objects to show some information. Each list item contains an object of DocumentMatchCount object which has structure like this -
Public class DocumentMatchCount
{
public DocumentInfo documentInfo;
public string count;
}
The DocumentInfo class has different attributes like Filename and Path etc. Every item in the listbox will show Filename, its Path and the count which is the number of times the given input string (which user is searching) appears in the document.
XAML code:
<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>
Problem is list items appears to be there in the list but they are not visible. Also, if I click on any item the code on click event of it get executed perfectly. But just the list items are not visible.
I know this must be an easy fix but I am quite new to this desktop app development so not getting whats wrong going here.
Any help is greatly appreciated. Thanks!
Upvotes: 0
Views: 485
Reputation: 157
Ok, I figured out what was the issue. I had not set the properties in the DocumentMatchCount class. I declared those and used the for binding and now its showing correctly.
Thanks Mohit for your help!!
Upvotes: 0