© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
2 replies
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.
private void MyListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
      //selectedFerry = (Ferry)MyListBox.SelectedItem;

      if (MyListBox.SelectedItem != null)
      {
          Console.WriteLine("Hey");
      }             
  }
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Problems with wrapping in wpf Listbox
C#CC# / help
3y ago
WPF ListBox w/ Header Button IsEnabled Question
C#CC# / help
17mo ago
[WPF] How to edit multiple items in ListBox at once
C#CC# / help
3y ago