Reputation: 27
I can't get a text from listbox with SELECTEDITEM event but it doesn't and only return a string like "Li.Medicamento".
My code xaml:
<ListBox x:Name="list_enfer" Margin="38,210,40,65" Visibility="Collapsed">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding enfermedadasoc}"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My code in C# is the next:
private void visualizar_est_Click(object sender, System.EventArgs e)
{
MessageBox.Show(list_enfer.SelectedItem.ToString());
}
Upvotes: 0
Views: 77
Reputation: 222657
private void visualizar_est_Click(object sender, System.EventArgs e)
{
var mySelectedItem = list_enfer.SelectedItem as yourObject;
//Then you can access the property inside yourObject
MessageBox.Show(yourObject.enfermedadasoc.ToString());
}
Upvotes: 1