title: UWP Xaml GridViewItem: Remove margin
body: <p>I want to create a grid of images without any margin between them. I tried to achieve this through a <code>GridView</code>. If there is an easier way, please let me know.</p>
  
  <p>I found this answers on StackOverflow:</p>
  
  <p><a href="https://stackoverflow.com/a/10492464">https://stackoverflow.com/a/10492464</a></p>
  
  <p><a href="https://stackoverflow.com/a/23817931/5739170">https://stackoverflow.com/a/23817931/5739170</a></p>
  
  <p>And ended up with this code:
      </p>
  
  <pre><code>&lt;Page.Resources&gt;
      &lt;Style x:Key="MyGridViewItemStyle" TargetType="GridViewItem"&gt;
          &lt;Setter Property="Padding" Value="0" /&gt;
          &lt;Setter Property="Margin" Value="0" /&gt;
          &lt;Setter Property="BorderThickness" Value="0" /&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="GridViewItem"&gt;
                      &lt;GridViewItemPresenter ContentMargin="0" Padding="0" Margin="0" BorderThickness="0"/&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
  
      &lt;/Style&gt;
  &lt;/Page.Resources&gt;
  
  &lt;Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"&gt;
      &lt;StackPanel&gt;
          &lt;GridView ItemsSource="{x:Bind FieldList}" Margin="0,50,0,0" Padding="0" BorderThickness="0" ItemContainerStyle="{StaticResource MyGridViewItemStyle}" IsItemClickEnabled="True" ItemClick="OnItemClick"&gt;
              &lt;GridView.ItemTemplate&gt;
                  &lt;DataTemplate x:DataType="data:Field"&gt;
                      &lt;Image Width="20" Height="20" Margin="0" Source="{x:Bind ImagePath}"/&gt;
                  &lt;/DataTemplate&gt;
              &lt;/GridView.ItemTemplate&gt;
          &lt;/GridView&gt;
          &lt;TextBlock x:Name="text"&gt;Hallo!&lt;/TextBlock&gt;
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>But there is still a margin left:
  <a href="https://i.stack.imgur.com/5bb5s.png" rel="nofollow noreferrer">Screenshot</a></p>
  
  <p>I have also tried to use negative margins but when I use them clicks aren't recognized correctly anymore.</p>
  
  <p>How can I remove the margins?</p>