C# MVVM-生成ObservableCollection筛选器
我正在尝试创建一个可以筛选的列表。 首先在我的xaml中C# MVVM-生成ObservableCollection筛选器,c#,wpf,xaml,mvvm,C#,Wpf,Xaml,Mvvm,我正在尝试创建一个可以筛选的列表。 首先在我的xaml中 <CollectionViewSource x:Key="ExpectedGroup" Source="{Binding ExpectedListView, UpdateSourceTrigger=PropertyChanged}"> <CollectionViewSource.GroupDescriptions>
<CollectionViewSource x:Key="ExpectedGroup"
Source="{Binding ExpectedListView, UpdateSourceTrigger=PropertyChanged}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="InductedSites" />
</CollectionViewSource.GroupDescriptions>
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="InductedSites"/>
<scm:SortDescription PropertyName="PN_EmploymentType"/>
<scm:SortDescription PropertyName="FullName"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
**编辑
还有列表框
<ListBox Grid.Row="2" x:Name="lbExpected"
DataContext="{StaticResource ExpectedGroup}"
Background="{x:Null}" HorizontalContentAlignment="Stretch" IsSynchronizedWithCurrentItem="True"
Margin="0,2,0,0" FontSize="10.667">
但清单总是空的。
通过使我的listbox itemsource=ExpectedListView,我已经证明了这个过程是有效的。
我到处找,找不到我做错了什么。
感谢你的指点。斯科特您想要:
<ListBox ItemSource="{Binding Source={StaticResource ExpectedGroup}}" .../>
Not DataContext=“{StaticResource ExpectedGroup}”。我是为筛选编写的。它是强类型的,因此您可以获得智能感知和可测试性。我感谢您的回答。但这并不能帮助我解决眼前的问题,以及我做错了什么。我将进一步研究这一点。恐怕这仍然不起作用;不行。我目前正在研究所有可能的解决方案。真不敢相信我有这样的问题。
<ListBox Grid.Row="2" x:Name="lbExpected"
DataContext="{StaticResource ExpectedGroup}"
Background="{x:Null}" HorizontalContentAlignment="Stretch" IsSynchronizedWithCurrentItem="True"
Margin="0,2,0,0" FontSize="10.667">
<ListBox ItemSource="{Binding Source={StaticResource ExpectedGroup}}" .../>