title: How can I get SelectedItem and show Headers using ItemsControl?
body: <p>I am working on WPF Windows Application. I'm using ItemsControl to show collection list. Working on this I found there is no SelectedItem property in ItemsControl. Then how can I get the Selected Item from the ItemsControl. And also How can I display the Headers of ItemsControl.</p>
  
  <pre><code>&lt;ItemsControl ItemsSource="{Binding CustomSalesProducts, Mode=TwoWay}"&gt;
          &lt;ItemsControl.Template&gt;
              &lt;ControlTemplate TargetType="ItemsControl"&gt;
                  &lt;Border&gt;
                      &lt;ScrollViewer VerticalScrollBarVisibility="Auto"&gt;
                          &lt;ItemsPresenter/&gt;
                      &lt;/ScrollViewer&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/ItemsControl.Template&gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;VirtualizingStackPanel CanHorizontallyScroll="True" CanVerticallyScroll="True" Orientation="Vertical"/&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
          &lt;ItemsControl.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid x:Name="SalesGrid" Background="White"&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="Auto"/&gt;
                          &lt;RowDefinition Height="Auto"/&gt;
                          &lt;RowDefinition Height="Auto"/&gt;
                      &lt;/Grid.RowDefinitions&gt;
                      &lt;controls:HeaderedContentControl Header="{Binding ProductName, Mode=TwoWay}" Margin="{DynamicResource Margin4}" Style="{DynamicResource HeaderedContentControlStyle}" HorizontalContentAlignment="Right"&gt;
                      &lt;/controls:HeaderedContentControl&gt;
                      &lt;TextBox Text="{Binding OrderQty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Quantity" /&gt;
                      &lt;TextBlock Text="{Binding UnitSalePrice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1" Margin="{StaticResource Margin4}" ToolTip="Price"/&gt;
                      &lt;TextBox Text="{Binding Discount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Grid.Row="1" Margin="{StaticResource Margin4}" Style="{DynamicResource MiniTextBoxStyle}" ToolTip="Discount"/&gt;
                      &lt;TextBlock Text="{Binding TaxAmount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="3" Grid.Row="1" Margin="{StaticResource Margin4}" ToolTip="Tax Amount"/&gt;
                      &lt;TextBlock Text="{Binding LineTotal, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="4" Grid.Row="1" Margin="{StaticResource Margin4}" ToolTip="Total"/&gt;
  
                  &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>Thanks,</p>