与列表项的可见性绑定
Visibility binding with list item
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
> 0.
然后使用 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>
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
> 0.
然后使用 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>