WPF绑定到IsSelected视图模型不设置那些不在列表中被证明项目 [英] WPF Binding IsSelected to ViewModel doesn't set items that haven't been shown in the List
问题描述
我有一个视图模型
有我在 ListView控件绑定一个
XAML来在我看来,模型中的 IsSelected
属性.ItemContainerStyle IsSelected
属性。
I have a ViewModel
that has an IsSelected
property which I bind in my ListView.ItemContainerStyle
XAML to an IsSelected
property in my view model.
我提出申请,并填充视图模型集合(这是在我的显示的ListView
)有很多的项目,说一下2000。然后我选择的一切通过 CTRL-A 骨节病>列表。在我看来,模型集合的项目只能获得 IsSelected
对于那些在的ListView
中可见的项目设置。如果我页面向下列表中的 IsSelected
被设置得到显示任何物品。如果通过所有的项目我页,然后在我看来,模型中的所有项目都在 IsSelected
属性设置为true。
I bring up the application and populate the view model collection (which is shown in my ListView
) with a lot of items, say about 2000. Then I select everything in the list via Ctrl-A. The items in my view model collection only get the IsSelected
set for the items that are visible in the ListView
. If I page down through the list the IsSelected
gets set for whatever items get shown. If I page through all the items then all the items in my view model have the IsSelected
property set to true.
下面是我的XAML在列表视图绑定 IsSelected
我的视图模型:
Here is my XAML for binding the IsSelected
in the list view to my view model:
<ListView Margin="5" ItemsSource="{Binding FilteredComparisonList}" x:Name="comparisonListView">
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Source filename" DisplayMemberBinding="{Binding ImageFile.BaseFilename}" Width="Auto" />
</GridView>
</ListView.View>
</ListView>
为什么不是 IsSelected
在我看来,模型中的所有项目设置为true,当我选择在 ListView中的所有项目
?
Why isn't IsSelected
for all the items in my view model set to true when I select all the items in the ListView
?
推荐答案
的MVVM方式做,这将是覆盖按Ctrl-A快捷键与自己的选命令(用Ctrl-A的快捷方式创建一个SellectAll命令) 。实施将设置视图模型IsSelected。
The MVVM way to do this would be to override the Ctrl-A shortcut with your own SelectAll command (Create a SellectAll command with a shortcut of Ctrl-A). The implementation will set IsSelected on the view models.
在你看来你的IsSelected属性需要有一个双向绑定到您的视图模式,使项目出现在视图中选择。
Your IsSelected property in your view needs to have a two way binding to your view model so that the items appear selected in your view.
我不认为关闭虚拟化是所必要的。
I dont think turning off virtualisation is nessesary.
希望这有助于。
这篇关于WPF绑定到IsSelected视图模型不设置那些不在列表中被证明项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!