title: Viewport width slightly wider than real view window WPF
body: <p>I prepared my own <code>DataTemplate</code> to display my own Item class objets. To set the width I use binding to <code>ViewportWidth</code> of <code>ScrollViewer</code>. This is how:</p>
  
  <pre><code>&lt;DataTemplate x:Key="MyItemTemplate"&gt;
          &lt;Grid Margin="5" HorizontalAlignment="Stretch"
                Width="{Binding ViewportWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}}"&gt;
              ...
          &lt;/Grid&gt;
      &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>How I display data:</p>
  
  <pre><code>&lt;TabItem Header="Shop"&gt;
              &lt;!--&lt;ScrollViewer&gt;--&gt;
                  &lt;ListView Name="ShopListView" ItemsSource="{Binding itemList}"
                        ItemTemplate="{StaticResource MyItemTemplate}"
                        ItemContainerStyle="{StaticResource alternatingListViewItemStyle}"
                        AlternationCount="2"
                        ScrollViewer.CanContentScroll="True"
                        /&gt;
              &lt;!--&lt;/ScrollViewer&gt;--&gt;
  &lt;/TabItem&gt;
  </code></pre>
  
  <p>The issue is the <code>grid</code> that makes my <code>DataTemplate</code> is sliglty broader - it overlaps the right border of the <code>View Window</code>.</p>
  
  <p><strong>EDIT</strong>
  <a href="https://i.stack.imgur.com/W6jIF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W6jIF.png" alt="The problem is visible on the right side"></a>
  Buttons on their right edges are cut.</p>
  
  <pre><code>&lt;Style x:Key="alternatingListViewItemStyle" TargetType="{x:Type ListViewItem}"&gt;
          &lt;Style.Triggers&gt;
              &lt;!-- setting up triggers for alternate background colors --&gt;
              &lt;Trigger Property="ItemsControl.AlternationIndex" Value="1"&gt;
                  &lt;Setter Property="Background" Value="#FF4C85FF"&gt;&lt;/Setter&gt;
              &lt;/Trigger&gt;
              &lt;Trigger Property="ItemsControl.AlternationIndex" Value="2"&gt;
                  &lt;Setter Property="Background" Value="#FFFF8C7C"&gt;&lt;/Setter&gt;
              &lt;/Trigger&gt;
          &lt;/Style.Triggers&gt;
      &lt;/Style&gt;
  </code></pre>