title: ListBox selected trigger in WPF not triggering
body: <p>I setting the selected item of a list box from the code behind as follows</p>
  
  <pre><code>private void AvailableItem_Click(object sender, RoutedEventArgs e)
      {
          object clicked = (e.OriginalSource as FrameworkElement).DataContext;
          var lbi = AvailableItem.ItemContainerGenerator.ContainerFromItem(clicked) as ListBoxItem;
          lbi.IsSelected = true;
      }
  </code></pre>
  
  <p>I have added a trigger as follows to change the selected item background color</p>
  
  <pre><code>&lt;Style.Triggers&gt;
                          &lt;Trigger Property="IsSelected" Value="True"&gt;
                              &lt;Setter Property="Foreground" Value="White" /&gt;
                              &lt;Setter Property="Background" Value="Black"/&gt;
                          &lt;/Trigger&gt;
  &lt;/Style.Triggers&gt;
  </code></pre>
  
  <p>The problem here is that the color does not change as expected. I tried adding trigger for IsSelected value to be false and it works, but IsSelected true is not triggered. I am confused as to why this happens.</p>
  
  <p>EDIT:</p>
  
  <p>Here is the complete binding code:</p>
  
  <pre><code>&lt;ListBox  Height="600"  Name="AvailableItem" Width="320" Grid.Column="1" ButtonBase.Click="AvailableItem_Click" Background="#00000000" BorderBrush="LightBlue" HorizontalContentAlignment="Stretch"&gt;
              &lt;ListBox.ItemTemplate&gt;
                  &lt;DataTemplate&gt;
                      &lt;Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;
                          &lt;Grid.ColumnDefinitions&gt;
                              &lt;ColumnDefinition Width="2*"/&gt;
                              &lt;ColumnDefinition Width="*"/&gt;
                          &lt;/Grid.ColumnDefinitions&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="*"/&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;TextBlock Text="{Binding Path = SomeText}" FontSize="14" Foreground="Black" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" Margin="0,0,0,0"/&gt;
                          &lt;Button Command="{Binding ElementName=root, Path=DataContext.SomeCommand}" Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="#BF000000" BorderBrush="Transparent" Foreground="White" Content="..." Width="25" Height="25" Margin="5,0,5,0"&gt;
                          &lt;/Button&gt;
                      &lt;/Grid&gt;
                  &lt;/DataTemplate&gt;
              &lt;/ListBox.ItemTemplate&gt;
              &lt;ListBox.ItemContainerStyle&gt;
                  &lt;Style TargetType="{x:Type ListBoxItem}"&gt;
                      &lt;Style.Triggers&gt;
                          &lt;Trigger Property="IsSelected" Value="True"&gt;
                              &lt;Setter Property="Foreground" Value="Yellow" /&gt;
                              &lt;Setter Property="Background" Value="Red"/&gt;
                          &lt;/Trigger&gt;
                          &lt;Trigger Property="IsSelected" Value="False"&gt;
                              &lt;Setter Property="Foreground" Value="Black" /&gt;
                              &lt;Setter Property="Background" Value="Transparent"/&gt;
                          &lt;/Trigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/ListBox.ItemContainerStyle&gt;
  </code></pre>
  
  <p></p>