I have a problem, I need to get the selected Item from a ContextMenu in a LongListSelector.
Before I was using a normal ListBox and I did it with:
var selectedItem = myList.ItemContainerGenerator.ContainerFromItem(menuItem.DataContext) as ListBoxItem;
But now I’m using the LongListSelector and this method doesn’t work.
Who can I do it?
If the LongListSelector is databound, you can use the
DataContextproperty to access the selected item.assuming your LongListSelector is databound to a list of MyObject objects.