title: WPF keep control from affecting scrollviewer width?
body: <p>Is there a way to prevent a wrap panel (or other control) from participating in a scrollviewers width calculation?  For example below, I'd like the wrap panel to stay within the width created by other controls but not directly affect the width calculation.  (i.e.) I'd like behavior similar to if Auto was off, but still allow horizontal scrolling of other content gets wider.</p>
  
  <pre><code>&lt;Window x:Class="MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;ScrollViewer HorizontalScrollBarVisibility="Auto"&gt;
          &lt;Grid&gt;
              &lt;Grid.ColumnDefinitions&gt;
                  &lt;ColumnDefinition Width="100" /&gt;
                  &lt;ColumnDefinition Width="1*" /&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;RowDefinition Height="Auto" /&gt;
                  &lt;RowDefinition Height="Auto" /&gt;
              &lt;/Grid.RowDefinitions&gt;
              &lt;WrapPanel Grid.Column="1" Name="ctlWrap" /&gt;
              &lt;TextBox Grid.Row="1" Grid.Column="1" Width="100" HorizontalAlignment="Left" Name="ctlText" /&gt;
              &lt;StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal"&gt;
                  &lt;Button Click="Button_Click"&gt;Add Wrap&lt;/Button&gt;
                  &lt;Button Click="Button_Click_1"&gt;Remove Wrap&lt;/Button&gt;
                  &lt;Button Click="Button_Click_2"&gt;Add Text&lt;/Button&gt;
                  &lt;Button Click="Button_Click_3"&gt;Remove Text&lt;/Button&gt;
              &lt;/StackPanel&gt;
          &lt;/Grid&gt;
      &lt;/ScrollViewer&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Here's the code I used for the buttons:</p>
  
  <pre><code>Class MainWindow 
  
  Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
      ctlWrap.Children.Add(New Button With {.Content = "Button " &amp; ctlWrap.Children.Count + 1})
  End Sub
  
  Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
      If ctlWrap.Children.Count Then
          ctlWrap.Children.RemoveAt(ctlWrap.Children.Count - 1)
      End If
  End Sub
  
  Private Sub Button_Click_2(sender As Object, e As RoutedEventArgs)
      ctlText.Width += 30
  End Sub
  
  Private Sub Button_Click_3(sender As Object, e As RoutedEventArgs)
      If ctlText.Width &gt; 60 Then ctlText.Width -= 30
  End Sub
  End Class
  </code></pre>