title: Uniform Grid as Panel Template for All Items in ItemsControl Except the First
body: <p>I'm working on a progress wizard. I defined it as a style based on the ItemsControl. I have an ItemTemplateSelector with two DataTemplates, one for the first item and one for the rest of the items. I have it working correctly except for one really small issue that is super tricky to fix. There is a gap between the first item and the second item. <a href="https://i.stack.imgur.com/dTDMI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dTDMI.png" alt="enter image description here"></a>
  This is what the control should look like: <a href="https://i.stack.imgur.com/Qoi9s.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Qoi9s.png" alt="enter image description here"></a> The gap occurs because I'm using a uniform grid and so all of the columns are sized the same, even though the first one has no line. Using a uniform grid is important though because I want everything on one row and I want the control to stretch to fill the available space as it grows. I've tried not using the uniform grid but I end up either having issues with the margins or with not filling the available space. how can I fix this gap? <br></p>
  
  <p>Here's the code:</p>
  
  <pre><code>&lt;Style x:Key="WizardProgressBar" TargetType="{x:Type ItemsControl}"&gt;
          &lt;Style.Resources&gt;
              &lt;DataTemplate x:Key="FirstItem"&gt;
                  &lt;Grid&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;Ellipse Name="ellipse"  HorizontalAlignment="Left" Height="32" Width="32"  /&gt;
                  &lt;/Grid&gt;
                  &lt;DataTemplate.Triggers&gt;
                      &lt;DataTrigger Binding="{Binding Completed}" Value="False"&gt;
                          &lt;Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource DisabledBrush}" /&gt;
                      &lt;/DataTrigger&gt;
                      &lt;DataTrigger Binding="{Binding InProgress}" Value="True"&gt;
                          &lt;Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource PrimaryTextBrush}"/&gt;
                      &lt;/DataTrigger&gt;
                  &lt;/DataTemplate.Triggers&gt;
              &lt;/DataTemplate&gt;
  
  
              &lt;DataTemplate x:Key="OtherItem"&gt;
                  &lt;Grid&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="*"/&gt;
                          &lt;ColumnDefinition Width="Auto"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;Ellipse Name="ellipse"  Grid.Column="1" HorizontalAlignment="Left" Height="32" Width="32" /&gt;
                      &lt;Line Name="leftPath" Grid.Column="0" X1="0" Y1="16" 
                                X2="{Binding ActualWidth, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}" Y2="16" /&gt;
                  &lt;/Grid&gt;
                  &lt;DataTemplate.Triggers&gt;
                      &lt;DataTrigger Binding="{Binding Completed}" Value="False"&gt;
                          &lt;Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource DisabledBrush}" /&gt;
                          &lt;Setter TargetName="leftPath" Property="Stroke" Value="{DynamicResource DisabledBrush}"/&gt;
                      &lt;/DataTrigger&gt;
                      &lt;DataTrigger Binding="{Binding InProgress}" Value="True"&gt;
                          &lt;Setter TargetName="ellipse" Property="Stroke" Value="{DynamicResource PrimaryTextBrush}"/&gt;
                          &lt;Setter TargetName="leftPath" Property="Stroke" Value="{DynamicResource PrimaryTextBrush}"/&gt;
                      &lt;/DataTrigger&gt;
                  &lt;/DataTemplate.Triggers&gt;
              &lt;/DataTemplate&gt;
          &lt;/Style.Resources&gt;
          &lt;Setter Property="ItemsPanel"&gt;
              &lt;Setter.Value&gt;
                  &lt;ItemsPanelTemplate&gt;
                      &lt;UniformGrid Rows="1"/&gt;
                  &lt;/ItemsPanelTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
          &lt;Setter Property="ItemTemplateSelector"&gt;
              &lt;Setter.Value&gt;
                  &lt;wpf:ItemsDataTemplateSelector  FirstItem="{StaticResource FirstItem}" OtherItem="{StaticResource OtherItem}" /&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p><br></p>
  
  <pre><code>public class ItemsDataTemplateSelector : DataTemplateSelector
      {
          public DataTemplate FirstItem { get; set; }
          public DataTemplate OtherItem { get; set; }
  
          public override DataTemplate SelectTemplate(object item, DependencyObject container)
          {
              var itemsControl = ItemsControl.ItemsControlFromItemContainer(container);
              var returnTemplate = (itemsControl.ItemContainerGenerator.IndexFromContainer(container) == 0) ? FirstItem : OtherItem;
              return returnTemplate;
          }
      }
  </code></pre>