C# 使用SelectionMode=";绑定嵌套列表框中的选定项;“多重”;和BindableSelection扩展
我正在开发一个具有MVVM模式的Windows Phone 8.1应用程序(我使用Prism作为框架) 目标是在几个列表中获取所选项目,如下所示:C# 使用SelectionMode=";绑定嵌套列表框中的选定项;“多重”;和BindableSelection扩展,c#,xaml,mvvm,data-binding,windows-phone-8.1,C#,Xaml,Mvvm,Data Binding,Windows Phone 8.1,我正在开发一个具有MVVM模式的Windows Phone 8.1应用程序(我使用Prism作为框架) 目标是在几个列表中获取所选项目,如下所示: public class SymbolsGroupViewModel : ViewModel { private readonly INavigationService _navigationService; private readonly DataService _dataService; private Observa
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); }
}
}
我有以下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}">
...
它应该使用WinRT XAML工具包中的BindableSelection
扩展,如下所示:
它适用于非嵌套列表,但是当我将解决方案调整为嵌套列表时,SelectedItems
列表包含0个元素
有人知道是否可以在嵌套列表中使用此扩展,如果可以,我做错了什么吗?
谢谢你的帮助。我已经找到了错误所在,所以我会留下答案,以防有人有类似的问题 在嵌套列表中,绑定应按以下方式编写:
Extensions:ListBoxExtensions.BindableSelection="{Binding SelectedItems, Mode=TwoWay}"
- 在那里提供
是个坏主意ElementName
- 我以前没有注意到,每种列表都有单独的扩展。在我的情况下,我应该使用
ListBoxExtensions
Extensions:ListBoxExtensions.BindableSelection="{Binding SelectedItems, Mode=TwoWay}"