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...?
Hello Eli,
Unfortunately, there are no samples for a custom GalleryItem class, so you would have to create one that meets the needs of your application.
Additionally, if you would like to have this as a new feature implemented in our future releases, what I can suggest you is submitting a product idea. You can suggest new product ideas for future versions (or vote for existing ones) at http://ideas.infragistics.com.
There are many benefits to submitting a product idea:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
Steps to create your idea:
1. Log into the Infragistics Product Idea site at http://ideas.infragistics.com (creating a new login if needed).
2. Navigate to the product / platform channel of your choice (e.g. WPF, Windows Forms, ASP.NET, HTML5 / Ignite UI, iOS / NucliOS, etc.)
3. Add your product idea and be sure to be specific and provide as much detail as possible.
The Product Idea site puts you in the driver’s seat and allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Thank you for contacting Infragistics.
Regards, Ivan Kitanov
Hi, thank you for this suggestion.
This would be a perfect solution for a fixed gallery, but in my case, the gallery is being built in code-behind based on the number of pre-defined items the user chosen. I assume I can work around that by 'saving' the correct Y values before the gallery is created, however, the bigger concern is that the location of each item can be changed since you can minimize and maximize the gallery. see attachments.
I think the only way would be to create my own GalleryItem. Do you have a sample in-which the gallery-item is a custom control?
I’ve found out a simpler solution to this, that doesn’t require creating a custom GalleryItem. It captures the Y position of where the context menu is shown on the screen and depending on the Y coordinate it determines, which GalleryItem was clicked.
To determine this Y coordinate inside the Opened event of the context menu you would need to use the TranslateToPoint method of the context menu and to provide the GalleryTool as a parameter to the method. It should look something similar to this:
private void ContextMenu_Opened(object sender, RoutedEventArgs e)
{
Point position = contextMenu.TranslatePoint(new Point(0, 0),galleryTool1);
positionY = position.Y;
}
To determine the bounds of each GalleryItem I have used SNOOP as an element inspecting tool. I suggest you using whichever element inspecting tool in order to determine the min/max Y coordinates of each gallery in item, since they would be different from the ones I am using inside the sample that I am attaching. Based on these Y coordinates, the GalleryItem could be defined by the order they appear in the GalleryTool.
Please test the sample on your side and let me know if this is an accurate demonstration of what you are trying to achieve or if you have any questions.
XamRibbonDeleteGalleryItem.zip
Hi. thank you for your sample - the approach in the sample isn't good enough, I am looking for right-clicking per item and not via a list.
It seems that the only way is to create a custom gallery item. do you have a sample for that please?
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.
XamRibbonGalleryItemDelete.zip