C
C#2mo ago
Amin

WPF Acquiring an Item clicked in a ListBox

As stated I'm trying to acquire a specific dataype from an object that's in a listbox, but I'm just trying to get a hand at understanding how it works.
C#
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//selectedFerry = (Ferry)MyListBox.SelectedItem;

if (MyListBox.SelectedItem != null)
{
Console.WriteLine("Hey");
}
}
C#
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//selectedFerry = (Ferry)MyListBox.SelectedItem;

if (MyListBox.SelectedItem != null)
{
Console.WriteLine("Hey");
}
}
In this piss poor example that I made, my understanding is that if I select an item by clicking on it in the list, it prints out the specific message that I wrote. By that logic, would it be possible for me to acquire specific data that is in the list and storing it in a variable?
1 Reply
leowest
leowest2mo ago
Give a look here https://wpf-tutorial.com/list-controls/listbox-control/ if u scroll down a bit there is a section called "Working with ListBox selection"