title: Bind UniformGrid Columns based on parent Width
body: <p>I'm trying to bind a UniformGrid Columns property in a ItemsControl.</p>
  
  <p>So far I have:</p>
  
  <pre><code>&lt;ScrollViewer x:Name="scroll" VerticalScrollBarVisibility="Auto"&gt;
      &lt;ItemsControl ItemsSource="{Binding}" &gt;
          &lt;ItemsControl.ItemsPanel&gt;
              &lt;ItemsPanelTemplate&gt;
                  &lt;UniformGrid&gt;
                      &lt;UniformGrid.Columns&gt;
                          &lt;MultiBinding Converter="{StaticResource Columns}"&gt;
                              &lt;Binding RelativeSource="{RelativeSource Self}" /&gt;
                              &lt;Binding Source="{x:Reference scroll}" /&gt;
                          &lt;/MultiBinding&gt;
                      &lt;/UniformGrid.Columns&gt;
                  &lt;/UniformGrid&gt;
              &lt;/ItemsPanelTemplate&gt;
          &lt;/ItemsControl.ItemsPanel&gt;
  
      &lt;/ItemsControl&gt;
  &lt;/ScrollViewer&gt;
  </code></pre>
  
  <p>And in the converter:</p>
  
  <pre><code>const double TileWidth = 154;
  public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  {
      double width, aWidth;
      UniformGrid grid = values[0] as UniformGrid;
      ScrollViewer scroll = values[1] as ScrollViewer;
      var gw = grid.Width;
      var gaw = grid.ActualWidth;
  
      aWidth = scroll.ActualWidth;
      width = aWidth - (scroll.Padding.Left + scroll.Padding.Right);
  
      return 3;
  
      // return width / TileWidth;
  }
  </code></pre>
  
  <p>I can't get any of the width's of the parent controls to determine how many columns I want to display.  They are either <code>0.0</code> or <code>NaN</code>.</p>
  
  <p>How can I get a parent's width to determine how much space is available?</p>