本文介绍了将嵌套的ListBox中的选定项目与SelectionMode =“Multiple”和BindableSelection扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在开发具有MVVM模式的Windows Phone 8.1应用程序(我使用Prism作为框架)I'm developing a Windows Phone 8.1 app with MVVM pattern (I'm using Prism as a framework)目标是将所选项目很少有这样的列表:The goal is to get the selected items in a few lists, like that: 我有以下XAML: <ListView x:Name="abc" ItemsSource="{Binding Symbols}"> <ListView.ItemTemplate> <DataTemplate> <StackPanel> <ListBox SelectionMode="Multiple" ItemsSource="{Binding List}"Extensions:ListViewExtensions.BindableSelection="{Binding SelectedItems, ElementName=abc, Mode=TwoWay}"> ...在ViewModel中:and in the ViewModel: public List<SymbolsGroupViewModel> Symbols { get { return _symbols ?? (_symbols = _dataService.Symbols.GetGroupViewModels()); } set { _symbols = value; } }其中class SymbolsGroupViewModel 看起来像:where class SymbolsGroupViewModel looks like that:public class SymbolsGroupViewModel : ViewModel{ private readonly INavigationService _navigationService; private readonly DataService _dataService; private ObservableCollection<Symbol> _selectedItems = new ObservableCollection<Symbol>(); public SymbolsGroupViewModel(INavigationService navigationService, DataService dataService) { _navigationService = navigationService; _dataService = dataService; } public SymbolsGroupViewModel() { } public Symbol Header { get; set; } public List<Symbol> List { get; set; } public ObservableCollection<Symbol> SelectedItems { get { return _selectedItems; } set { SetProperty(ref _selectedItems, value); } }}应该使用 BntableSelection 从WinRT XAML Toolkit的扩展名,如下所示: http://stackoverflow.com / a / 25430935/5194338 It is supposed to use the BindableSelection extension from WinRT XAML Toolkit, like here:http://stackoverflow.com/a/25430935/5194338 它适用于没有嵌套列表的我,但是当我将解决方案调整为嵌套列表时, SelectedItems 列表包含0个元素。It works for me with NOT nested lists, however when I adapt the solution to nested list, the SelectedItems lists contain 0 elements. 有人知道是否可以在嵌套列表中使用此扩展名,如果是,我做错了什么? 感谢您的帮助。推荐答案我发现错误在哪里,所以我会离开答案,以防有人有类似的问题... I've found where the mistake was so I'll leave the answer in case someone had similar problem...在嵌套列表绑定应该写成如下:In the nested list the binding should have been written as below:Extensions:ListBoxExtensions.BindableSelection="{Binding SelectedItems, Mode=TwoWay}" 给予 ElementName 是一个坏主意 我以前没有注意到,那里是各种列表的单独扩展。在我的情况下,我应该使用 ListBoxExtensions 。 Giving there ElementName was a bad ideaI haven't noticed before, that there are separate extensions for each kind of list. In my case I should have used ListBoxExtensions.希望这将有助于某人将来。Hope this will help someone in the future. 这篇关于将嵌套的ListBox中的选定项目与SelectionMode =“Multiple”和BindableSelection扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-16 23:37