【发布时间】:2014-12-24 14:03:26
【问题描述】:
我无法使用列表视图设置绑定多个选择,并在我将选择模式切换到单个和多个之间时记住选择。
上下文
我正在创建一个足球教练应用程序。列表视图将显示球员名单。在比赛日,我想要一种简单的方法来选择出现的球员。我想使用多重选择模式来允许用户选择出现的玩家。我将在应用栏中提供一个按钮,该按钮将通过转换器控制 SelectionMode。它将列表视图从单个切换到多个。这部分工作正常。我可以看到列表视图在 Single 和 Multiple 之间切换。
不能正常工作的部分是 Selected Items 的绑定。我一定遗漏了一些东西,因为可靠地绑定到 SelectedItems 属性似乎非常困难。迄今为止最有效的是 WinRTXamlToolkit 中的 ListViewExtentions,这是我在下面的 xaml 中展示的内容。 It seems to bind the items to the backing property in the view mode when the selection is made, however, when the SelectionMode is switched back to Single, the back property is cleared out.此外,在不修改扩展代码的情况下,它破坏了我的 SelectionMode 代码。 _listView.SelectedItems.Clear() 上的扩展存在灾难性故障。如果我删除该行,则 SelectionMode 将恢复工作。
我不想使用 WinRTXamlToolkit 中的 ListViewExtentions。我只在这里展示它,所以你知道我已经尝试过了。最终,我正在寻找绑定 SelectedItems 的正确解决方案。
这是列表视图 XAML。
<ListView ItemsSource="{Binding Roster}"
toolkitExt:ListViewExtensions.BindableSelection="{Binding SelectedPlayers, Mode=TwoWay}"
SelectionMode="{Binding IsEditingGameRoster, Converter={StaticResource ListViewSelectionModeFromBooleanNoneOrMultipleConverter}}">
<ListView.ItemTemplate>
<DataTemplate>
<!-- List View Display Not important for describing problem. -->
</DataTemplate>
</ListView.ItemTemplate>
命名空间为:xmlns:toolkitExt="using:WinRTXamlToolkit.Controls.Extensions"
视图模型具有以下属性: 名册:ObservableCollection IsEditingGameRoster : 布尔 SelectedPlayers : ObservableCollection
感谢任何演示绑定多重选择的示例,特别是如果它也处理切换选择模式。
谢谢, 汤姆
【问题讨论】:
标签: c# xaml listview windows-phone-8