Clyde Eisenbeis

Clyde Eisenbeis

  • 1.7k
  • 63
  • 11.9k

How do I detect a ListBox mouse click, then deselect other ListBoxes?

Mar 25 2024 2:47 PM

C# wpf - There are blue, yellow, and red cities in the ListBoxes (Pandemic Game).  This is the red ListBox xaml:

<ListBox x:Name="gLBxOriginalRedCities" 
            Margin="5,0,5,0" 
            Foreground="#ffffff" 
            Background="#ff0000" 
            MouseDoubleClick="gLBxOriginalRedCities_MouseDoubleClick"

A MouseDoubleClick jumps to the correct code in xaml.cs.

I've added MouseDown="gLBxOriginalRedCities_MouseDown". 

<ListBox x:Name="gLBxOriginalRedCities" 
            Margin="5,0,5,0" 
            Foreground="#ffffff" 
            Background="#ff0000" 
            MouseDown="gLBxOriginalRedCities_MouseDown"
            MouseDoubleClick="gLBxOriginalRedCities_MouseDoubleClick"

When I click a city in "gLBxOriginalRedCities" the code does not jump to

private void gLBxOriginalRedCities_MouseDown(object sender, MouseButtonEventArgs e)
{
    gLBxOriginalBlueCities.UnselectAll();
    gLBxOriginalYellowCities.UnselectAll();
}

How do I detect a ListBox mouse click, and then unselect the other ListBox items?

 


Answers (1)