Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1105
galleryitem contextmenu
posted

Hi,

I'm using the Ribbon Gallery and I'm trying to add the option to delete items from the Gallery by using context-menu.

How can I add a contextmenu that will identify the specific GalleryItem that I'm clicking on?

I assume I can create a custom gallery item but it seems to be an overkill for just this task, I'm sure I'm missing something here, right...?

Parents
No Data
Reply
  • 1700
    Offline posted

    Hello Eli,

    In order to create a custom contextmenu for the GalleryTool, what I can suggest you is using the ContextMenu property of the GalleryTool and then assigning a custom-created contextmenu. Identifying the GalleryItem is rather complicated and as you mentioned the easier way to do this may be to create your custom GalleryItem class that has a ContextMenu property and accessing the item inside the Click event of the “Delete” option inside the context menu by using the PlacementTarget property and deleting it from there. It should be something similar to this:

    MenuItem menuItem = sender as MenuItem;

                if (menuItem != null)

                {

                    ContextMenu contextMenu = menuItem.ContextMenu;

                    CustomGalleryItem item = (CustomGalleryItem)contextMenu.PlacementTarget;

                    galleryTool1.Items.Remove(item);

                }

    Additionally, I have created a small sample application, which demonstrates a rather simpler approach. Instead of creating a custom GalleryItem class I am adding MenuItem inside the contextmenu of the GalleryTool and for each GalleryItem the user has the option to delete/add it based on, whether the GalleryItem is present in the GalleryTool items collection or if the item has been removed.

    Please test the sample on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve, please feel free to modify it and send it back to me along with steps to reproduce.

    Please let me know if you have any questions.

    Regards,
    Ivan Kitanov

    XamRibbonGalleryItemDelete.zip

Children