WPF DataBinding(CommandParameter不工作)
我不能让我的绑定工作。我的ActiveView有一个ListView(x:Name =“MyListView”)以及视图模型,因为它是数据上下文。WPF DataBinding(CommandParameter不工作)
我有以下RibbonButton(RibbonControlLibrary):
<r:RibbonButton Label="Update Software"
LargeImageSource="/Ganymed.App.UI;component/Images/plain-update.png"
Command="{Binding ActiveView.DataContext.UpdateSoftwareCommand}"
CommandParameter="{Binding ActiveView.MyListView.SelectedItems}"/>
命令结合自身工作正常。但是我无法使CommandParameter工作。我想要沿着ActiveView的ListView的选定项目发送,以决定是否启用该命令。绑定CommandParameter时是否缺少某些东西?
为了阐明药结构:
MainWindow.xaml(包含RibbonButton,DataContext的= MainWindowViewModel)
MainWindowViewModel.cs包含属性的ActiveView
的ActiveView(包含MyListView,DataContext的= ActiveViewViewModel)
ActiveViewViewModel.cs包含UpdateSoftwareCommand
任何帮助都会很棒。由于
一种可能性:
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type r:RibbonButton}}, Path=SelectedItems}"
另外,你可以只添加属性SelectedItems你的视图模型,将其绑定并使其始终保持同步,并准备命令进行操作
您的解决方案无法正常工作。我猜这是行不通的,因为ListView并不是Visual Tree中Button的祖先。 – 2012-03-19 07:06:58
对不起,我的意思是把你的ViewModel绑定为ancenstor – 2012-03-21 22:29:52
应该不会吧蜜蜂ActiveView.MyListView而不是ActiveView.ListView,因为你说名称是“MyListView”? – SvenG 2012-03-16 15:09:36
嗨,这是我复制代码时的错误。我在示例中更改了名称,以免混淆其他人。 – 2012-03-16 15:14:21
您的UpdateSoftwareCommand代码的外观如何?如果您使用DelegateCommand,那么您应该使用DelegateCommand版本 –
Nikolay
2012-03-16 15:24:43