List<MyItem> Reports = new List<MyItem>();
public class MyItem
{
public int CountAnswers{ get; set; }
public DateTime DateTimeStartTime { get; set; }
}
我使用ListBox
Binding
中显示它
<ListBox Name="QuestionList" ItemsSource="{Binding Reports}">
<ListBox.ItemTemplate>
<DataTemplate >
<TextBlock Text="{Binding CountAnswers}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我想只显示CountAnswers大于0的项目。
我有100件商品,但只有少数商品有CountAnswers
&gt; 0
答案 0 :(得分:2)
然后使用LINQ ...
public IEnumerable<MyItem> ReportsWithAnwers
{
get
{
return Reports.Where(x => x.CountAnswers > 0);
}
}
<ListBox Name="QuestionList" ItemsSource="{Binding ReportsWithAnwers}">
<ListBox.ItemTemplate>
<DataTemplate >
<TextBlock Text="{Binding CountAnswers}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>