title: How to use different ItemsControl.ItemContainerStyle for different ItemsPanelTemplate
body: <p>I have an ItemsControl which uses different ItemsPanelTemplate based on certain condition. I want to have different ItemContainerStyle for each ItemsPanelTemplate (in fact, I want ItemsContainerStyle for only one of the templates). How can I achieve that? Here is the code I am using:</p>
  
  <pre><code>&lt;UserControl.Resources&gt;
      &lt;ItemsPanelTemplate x:Key="UGridItemsPanelTemplate"&gt;
        &lt;UniformGrid Name="MyUGrid" Columns="{Binding Columns}" Rows="{Binding Rows}"/&gt;
      &lt;/ItemsPanelTemplate&gt;
  
      &lt;ItemsPanelTemplate x:Key="GridItemsPanelTemplate"&gt;
        &lt;Grid Name="MyGrid" Loaded="MyGrid_Loaded"/&gt;
      &lt;/ItemsPanelTemplate&gt;
    &lt;/UserControl.Resources&gt;
  
    &lt;Grid&gt;
      &lt;!--ItemList has 1000+ items if IsMap is FALSE; using ItemsConatinerStyle in this case slows the UI down--&gt;
      &lt;ItemsControl  Name="MyPresenter" ItemsSource="{Binding ItemList}" Tag="{Binding IsMap}"&gt;
        &lt;ItemsControl.Style&gt;
          &lt;Style TargetType="{x:Type ItemsControl}"&gt;
            &lt;Setter Property="ItemsPanel" Value="{StaticResource UGridItemsPanelTemplate}"/&gt;
            &lt;Style.Triggers&gt;
              &lt;Trigger Property="Tag" Value="TRUE"&gt;
                &lt;!--I want to use ItemContainerStyle only for this template--&gt;
                &lt;Setter Property="ItemsPanel" Value="{StaticResource GridItemsPanelTemplate}"/&gt;
              &lt;/Trigger&gt;
            &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
        &lt;/ItemsControl.Style&gt;
  
        &lt;!--Use this style only if IsMap is TRUE--&gt;
        &lt;ItemsControl.ItemContainerStyle&gt;
          &lt;Style&gt;
            &lt;Setter Property="Control.Template"&gt;
              &lt;Setter.Value&gt;
                &lt;ControlTemplate TargetType="{x:Type ContentControl}"&gt;
                  &lt;ContentPresenter/&gt;
                &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
            &lt;Setter Property="Grid.Row" Value="{Binding GridRow}"/&gt;
            &lt;Setter Property="Grid.Column" Value="{Binding GridColumn}"/&gt;
          &lt;/Style&gt;
        &lt;/ItemsControl.ItemContainerStyle&gt;
  
        &lt;ItemsControl.ItemTemplate&gt;
          &lt;DataTemplate&gt;
            &lt;Border x:Name="Border1" Background="{Binding BorderVisible}"
                    BorderThickness="1" Padding="{Binding PaddingVal}"&gt;
              &lt;Button Name="ItemButton" Content="{Binding Label}" IsEnabled="{Binding IsButtonEnabled}" CommandParameter="{Binding}"/&gt;
            &lt;/Border&gt;
          &lt;/DataTemplate&gt;
        &lt;/ItemsControl.ItemTemplate&gt;
      &lt;/ItemsControl&gt;
    &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Thanks,
  RDV</p>