更新时间:2023-11-28 21:11:40
有几种方法可以做到:
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs args)
{
if (listBox1.SelectedIndex == -1) return;
Attractions first = listbox1.SelectedItem as Attractions ;
Attractions second = (Attractions)listBox1.Items[listBox1.SelectedIndex];
Attractions third = (sender as ListBox).SelectedItem as Attractions;
Attractions fourth = args.AddedItems[0] as Attractions;
Debug.WriteLine(" You selected " + first.AttractionName);
}
使用 SelectedItem(索引),您将获得一个属于您的 ItemsSource 集合类型的项目.拿到物品后,您就可以随心所欲地使用它.
With SelectedItem (Index) you get an item that is Type of your ItemsSource Collection. Once you get the item you can do what you want with it.