简体   繁体   中英

ListBox handling in wpf application

i have a list box and a button click event ,when i select an item in the list box and click on the button then the list item should appear in the text box...please help with the code.

private void Get_Click(object sender, RoutedEventArgs e)
{
        tb1.Text = listbox1.SelectedItem.ToString();

but it is not working, I'm getting like this but i just need item name to appear on textbox...

System.Windows.Controls.ListBoxItem: item name

Try this:

listbox1.SelectedItem.Content.ToString()

ListBoxes wrap all content in a ListBoxItem , which is what you are seeing. ListBoxItem inherits ContentControl and therefore has a Content property. This contains the object that you want.

http://msdn.microsoft.com/en-us/library/system.windows.controls.listboxitem.aspx

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM