Hello,
my problem is that the custom command I bound to the MenuTool surrounding a GalleryTool isn't executed. The CommandBindings are set correctly, because the same thing with an MenuTool containing Buttons works quite fine.
galleryMenu.Command = ChangeSkinCommand;galleryMenu.ShouldDisplayGalleryPreview = true;galleryMenu.ButtonType = MenuToolButtonType.Segmented;
Then I bound to the selectedItem ... to retrieve the correct command parameter:
Binding selectionBinding = new Binding("SelectedItem.Key");selectionBinding.Source = gallery;galleryMenu.SetBinding(MenuTool.CommandParameterProperty, selectionBinding);
This all works fine. The menu has the correct value as command parameter, but still it's not executed. What did I wrong?
Stef
Hello Ramajayam,
Here you can find a sample showing how to use Interactions to add command to the GalleryTool:
http://es.infragistics.com/community/forums/p/79890/402942.aspx
Can you please share a source code, instead of generically explaining in Text?
I want to have GallaryTool with each item binded to the command and each item should have a CommandParameter. Parameter is important. This will be helpful for me.
Thank you
I think it is possible to use the System.Windows.Interactivity.InvokeCommandAction to solve this problem. If you are using the StateButton mode for the Gallery, you just have this set EventName to ItemSelected, and then use a {Binding ...} to the SelectedItem to set up the Command or CommandParameter. This will just about work out-of-the-box, and you can do it all in XAML.
If you want to make it work with ItemClicked, there is a little more work involved; you'll need to write an attached property that stores the last item clicked.
Here's another vote for adding ICommandSource support for GalleryItem. Also, please add Text and Tooltips (example: Styles gallery in Word2010)
Thanks for the hint Andrew. I tried the solution with the ItemClicked Event, but it was already handled. So I use the PreviewMouseLeftButtonUp Event instead.
galleryMenu.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(this.GalleryMenuPreviewMouseLeftButtonUp);
/// <summary> /// Hack to execute a command for GalleryItems. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param> void GalleryMenuPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { MenuTool menu = sender as MenuTool; if (menu.ShouldDisplayGalleryPreview) { GalleryTool gallery = menu.Items[0] as GalleryTool; if (gallery != null) { if (menu.Command.CanExecute(gallery.SelectedItem.Text)) { menu.Command.Execute(gallery.SelectedItem.Text); } } } }
This is a bit hacky. I would like Infragistics would provide an other way to do this.