1

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

6
  • Shouldn't it bee ActiveView.MyListView instead of ActiveView.ListView, cause you say the name is "MyListView" ? Commented Mar 16, 2012 at 15:09
  • Hi that was my fault when copying the code. I have changed the name in the example to not confuse anybody else. Commented Mar 16, 2012 at 15:14
  • How does your code for UpdateSoftwareCommand look like? If you use DelegateCommand then you should use DelegateCommand<TypeOfCommandParameter> version Commented Mar 16, 2012 at 15:24
  • In our software solution we have an ActionCommand : ICommand implementation which we use as commands. Commented Mar 16, 2012 at 15:26
  • What is ActiveView, is it a UserControl? Commented Mar 16, 2012 at 16:32

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Your solution is not working. I guess it is not working since the ListView is not an Ancestor of the Button within the Visual Tree.
Sorry, I meant to put as the ancenstor whatever control that has the Binding to your ViewModel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.