title: WPF : How to bind Button's visibility inside ListBox ItemsControl using selecteditem information ?
body: <p>I have a list box binds to a ObservableCollection of Items. Each listboxItem contains a few textblocks and a few buttons. I would like to show the buttons inside the listboxItem only when the listbox item is selected or hightlight. If the listbox item is not highlighted, the button should be hidden. I tried to use datatrigger to bind to the IsSelected property. However it does not work. Please advice. thanks</p>
  
  <pre><code>        &lt;ListBox Name="LayoutListBox" SelectedItem="{Binding Path=SelectedLayout, Mode=TwoWay}" ItemsSource="{Binding Layouts}" SelectionMode="Single" HorizontalContentAlignment="Stretch"&gt;
        &lt;ListBox.ItemContainerStyle&gt;
          &lt;Style TargetType="ListBoxItem"&gt;
            &lt;Style.Resources&gt;
              &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Gray"/&gt;
              &lt;SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Gray"/&gt;
            &lt;/Style.Resources&gt;
          &lt;/Style&gt;
        &lt;/ListBox.ItemContainerStyle&gt;
        &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;Grid&gt;
              &lt;Grid.RowDefinitions&gt;
                &lt;RowDefinition Height="Auto" /&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;Border HorizontalAlignment="Stretch" Margin="2" CornerRadius="2" BorderBrush="#80808080" BorderThickness="1" Background="GhostWhite"&gt;
                      &lt;Grid&gt;
                              &lt;Grid&gt;
                                  &lt;Grid.ColumnDefinitions&gt;
                                      &lt;ColumnDefinition Width="*" /&gt;
                                      &lt;ColumnDefinition Width="*" /&gt;
                                      &lt;ColumnDefinition Width="*" /&gt;
                                      &lt;ColumnDefinition Width="*" /&gt;
                                  &lt;/Grid.ColumnDefinitions&gt;
                                  &lt;Grid.RowDefinitions&gt;
                                      &lt;RowDefinition Height ="*"/&gt;
                                      &lt;RowDefinition Height ="*"/&gt;
                                  &lt;/Grid.RowDefinitions&gt;
                                  &lt;DockPanel Grid.Row="1" Grid.Column="3" DockPanel.Dock="Right"&gt;
                                      &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Visibility="{Binding Path=ViewName, Converter={StaticResource Converter}, ConverterParameter=false}"&gt;
                                          &lt;Button ToolTip="Save"&gt;
                                              &lt;Image Source="/Common.View;component/LayoutManager/View/Images/PushPin.png" /&gt;
                                          &lt;/Button&gt;
                                          &lt;Button Click="EditButtonClick" ToolTip="Edit"&gt;
                                              &lt;Image Source="/Common.View;component/LayoutManager/View/Images/pencil.png" /&gt;
                                          &lt;/Button&gt;
                                          &lt;Button Click="DeleteButtonClick" ToolTip="Delete"&gt;
                                              &lt;Image Source="/Common.View;component/LayoutManager/View/Images/cross.png" /&gt;
                                          &lt;/Button&gt;
                                      &lt;/StackPanel&gt;
                                  &lt;/DockPanel&gt;
                              &lt;/Grid&gt;
                          &lt;/DockPanel&gt;
                      &lt;/Grid&gt;
                    &lt;/Border&gt;
            &lt;/Grid&gt;
          &lt;/DataTemplate&gt;
        &lt;/ListBox.ItemTemplate&gt;
      &lt;/ListBox&gt;
  </code></pre>