I need to access list box selected item from the user control. How can I manage that?
For example If I have ListBox x:Name="NewPicturesListBox" in MainPage.xaml
!--Panorama item New one-->
<controls:PanoramaItem Header="New one" Name="Pan1" >
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Margin="0,0,-12,0" x:Name="NewPicturesListBox"
And I need to access them from DetailControl.xaml.cs
The code below can give me the result within the MainPage.xaml, what about other pages, if any possibility exist?
if (NewPicturesListBox.ItemContainerGenerator != null)
{
var contextMenuListItem = (ListBoxItem)(NewPicturesListBox.ItemContainerGenerator.ContainerFromItem(((MenuItem)sender).DataContext));
if (contextMenuListItem != null)
{
var selectedPicture = (contextMenuListItem).Content as Picture;
You can have in you ViewModel and Property, lets call it selectedPicture that will hold the selectedValue, and bind to it from your XAML :