I have a list box and within the list box data template i have a context menu that opens when i hold the list item . But what i want to do is open the context menu on tapping on an image within the list item data template . How can i achieve this as the toolkit menu is not visible from the visual tree helper . Also i don't want to remove the context menu from the data template as i require info about the selected item which is passed through the data context . is there any way to do this or should i create my own custom pop-up?
You can open the context menu programmatically. Just add a tap event on the image control in your ListBox ItemTemplate and using XAML add the proper code exactly like you wanted to use the context menu with a button.
In the Image1_Tap event add this piece of code:
private void image1_Tap(object sender, GestureEventArgs e)
{
Image image = sender as Image;
ContextMenu contextMenu = ContextMenuService.GetContextMenu(image);
if (contextMenu.Parent == null)
{
contextMenu.IsOpen = true;
}
}
The XAML code would be something like this:
<Image>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
...
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Image>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.