title: WPF Listbox + Expander events
body: <p>I have an Expander in the ItemTemplate of a ListBox. Renders fine.  The issue I have run into is that I would like the ListBox_SelectionChanged event to fire when the expander is expanded and/or selected.  The MouseDown event does not seem to bubble up to the ListBox.  </p>
  
  <p>What I need is the SelectedIndex of the ListBox.  Because the ListBox_SelectionChanged does not get fired, the index is -1 and I cannot determine which item has been selected.</p>
  
  <p>The ListBox_SelectionChanged Event is fired if a user clicks on the Content of the Expander after it has been expanded.  If they only click on the expander, the event is not fired.  This is confusing to the user because visually, they think they have already clicked on that item when actually clicking on the Expander Header.  I need the ListBox Item selected when the user Expands the Expander because as far as the user is concerned, the item is now selected when it really isn't.</p>
  
  <p>Any suggests on how to get this to work or alternate ways of determining the SelectedIndex of the list box with expanders in it?</p>
  
  <p>Simplified code for reference:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication3.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"
      Loaded="Window_Loaded"&gt;
      &lt;Grid Name="Root"&gt;
          &lt;ScrollViewer&gt;
              &lt;ListBox SelectionChanged="ListBox_SelectionChanged" ItemsSource="{Binding}"&gt;
                  &lt;ItemsControl.ItemTemplate &gt;
                      &lt;DataTemplate&gt;
                          &lt;Border&gt;
                              &lt;Expander&gt;
                                  &lt;Expander.Header&gt;
                                      &lt;TextBlock Text="{Binding Path=Name}"/&gt;
                                  &lt;/Expander.Header&gt;
                                  &lt;Expander.Content&gt;
                                      &lt;StackPanel&gt;
                                          &lt;TextBlock Text="{Binding Path=Age}"/&gt;
                                          &lt;TextBlock Text="Line 2"/&gt;
                                          &lt;TextBlock Text="Line 3"/&gt;
                                      &lt;/StackPanel&gt;
                                  &lt;/Expander.Content&gt;
                              &lt;/Expander&gt;
                          &lt;/Border&gt;
                      &lt;/DataTemplate&gt;
                  &lt;/ItemsControl.ItemTemplate&gt;
              &lt;/ListBox&gt;
          &lt;/ScrollViewer&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Simple class for Binding:</p>
  
  <pre><code>public class Person
  {
      public string Name {
          get;
          set;
      }
  
      public int Age {
          get;
          set;
      }
  }
  </code></pre>
  
  <p>Creating and populating the data for binding:</p>
  
  <pre><code>private void Window_Loaded(object sender, RoutedEventArgs e) {
  
      data = new ObservableCollection&lt;Person&gt;();
  
      data.Add(new Person {
          Name = "One",
          Age=10
      });
  
      data.Add(new Person {
          Name = "Two",
          Age = 20
      });
  
      data.Add(new Person {
          Name = "Three",
          Age = 30
      });
  
      Root.DataContext = data;
  }
  </code></pre>
  
  <p>This is the event I need (really just the SelectedIndex I need)</p>
  
  <pre><code>private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) {
      ListBox box = (ListBox)sender;
  
      // This value is not set because events from Expander are not bubbled up to fire SelectionChanged Event
      int index = box.SelectedIndex;
  }
  </code></pre>