Skip to content

Instantly share code, notes, and snippets.

@wtuts
Last active August 29, 2015 14:03
Show Gist options
  • Save wtuts/444d7c78d693dfaac17d to your computer and use it in GitHub Desktop.
Save wtuts/444d7c78d693dfaac17d to your computer and use it in GitHub Desktop.
Listbox Selected item
//Event handler for marks button given in the mylisybox
private void Marks_button_click(object sender, RoutedEventArgs e)
{
//Get the data object that represents the current selected item
Resultclass myobject = (sender as Button).DataContext as Resultclass;
//Get the selected ListBoxItem container instance of the item whose marks button is pressed
ListBoxItem pressedItem = this.mylistbox.ItemContainerGenerator.ContainerFromItem(myobject) as ListBoxItem;
//Checks whether it is not null
if (pressedItem != null)
{
//Now you can get the name and marks of selected student from the myobject
//Display the name and marks of Selected Student in the textblocks given below the listbox.
Studentnameblock.Text = myobject.name;
marksblock.Text = myobject.marks.ToString(); ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment