Question

I can't get my binding to work. My ActiveView has a ListView (x:Name="MyListView") as well as a view model as it's data context.

I have the following 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}"/>

The command binding itself works fine. But I can't get the CommandParameter to work. I want to sent along the selected items of the ActiveView's ListView in order to decide whether or not to enabled the command. Am I missing something when binding the CommandParameter?

To clarify the structue:

MainWindow.xaml (contains the RibbonButton, DataContext = MainWindowViewModel)

MainWindowViewModel.cs contains the property ActiveView

ActiveView (contains the MyListView, DataContext = ActiveViewViewModel)

ActiveViewViewModel.cs contains the UpdateSoftwareCommand

Any help would be great. Thanks

Was it helpful?

Solution

One possibility :

 CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type r:RibbonButton}}, Path=SelectedItems}"

Another, you could just add a property SelectedItems to your ViewModel, bind it and have it always in sync and ready for command to operate on

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top