【发布时间】:2010-12-03 09:02:38
【问题描述】:
我有一个简单绑定到集合的列表框。该集合有一个子集合 (StepDatas)。我想绑定到子集合的计数,但使用 WHERE 语句。我可以绑定到 ChildCollection.Count 但在需要添加 lambda 表达式时会迷路。这是 XAML:
<ListBox Height="Auto" Style="{StaticResource ListBoxStyle1}" Margin="4,46,4,4" x:Name="lstLeftNavigation" Background="{x:Null}" SelectionChanged="lstLeftNavigation_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="180" Margin="2,2,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" d:LayoutOverrides="Width" MinHeight="36">
<TextBlock Text="{Binding StepNm}" x:Name="tbStepNm" Margin="10,0,34,0" TextWrapping="Wrap" FontFamily="Portable User Interface" Foreground="White" FontSize="10" FontWeight="Bold" VerticalAlignment="Center"/>
<Image Height="37" HorizontalAlignment="Right" Margin="0" VerticalAlignment="Center" Width="37" Source="Images/imgIcoChecked.png" Stretch="Fill"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
以上方法绑定到子集合的计数。但是,我希望显示满足特定条件的子集合的计数。在这种特定情况下,子集合具有已完成的属性 (bool)。所以...我想显示计数 StepDatas.Where(x => x.Completed == true).Count.
这有可能吗?感谢您的帮助!
【问题讨论】:
标签: silverlight xaml binding lambda