title: WPF - Adopt size of parent
body: <p>I'm trying to figure out the best way to size some controls but can't quite get it right. I have a window that adds on a custom control:</p>
  
  <pre><code>&lt;Grid x:Name="LayoutRoot"&gt;
      &lt;my:RateGraph Grid.Column="0" x:Name="rateGraph1" Height="88" Width="380" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>I then wish to size the sub-components of this control defined in the XAML to fill either the height, width or both. What I find however is that if I take off the explicit width/height and try and use something like VerticalAlignment="Stretch" then I get a control of size 0... What am I doing wrong?</p>
  
  <pre><code>&lt;rb:RateBase x:Class="RateBar.RateGraph"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
               xmlns:rb="clr-namespace:RateBar"
               xmlns:sd="clr-namespace:System.Windows.Data"
               mc:Ignorable="d"&gt;
      &lt;RangeBase.Resources&gt;
          &lt;rb:JScriptConverter x:Key="JScript" TrapExceptions="False"/&gt;
          &lt;ControlTemplate x:Key="rateGraphTemplate" TargetType="{x:Type rb:RateBase}"&gt;
              &lt;Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;
                  &lt;rb:Axis Width="320" Height="88"/&gt;
                  &lt;Rectangle Height="88" Fill="#9690EE90" x:Name="progress"&gt;
                      &lt;Rectangle.Width&gt;
                          &lt;MultiBinding Converter="{StaticResource JScript}" ConverterParameter="values[0]/values[1]*values[2]"&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Value"/&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Maximum"/&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Width"/&gt;
                          &lt;/MultiBinding&gt;
                      &lt;/Rectangle.Width&gt;
                  &lt;/Rectangle&gt;
                  &lt;Polygon Fill="#FF06B025" x:Name="graph" /&gt;
                  &lt;Label Canvas.Left="0" Width="380" HorizontalContentAlignment="Right" Foreground="Black" Content="{Binding Path=Caption, RelativeSource={RelativeSource TemplatedParent}}"&gt;
                      &lt;Canvas.Bottom&gt;
                          &lt;MultiBinding Converter="{StaticResource JScript}" ConverterParameter="(values[2]*0.8)/values[1]*values[0]"&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Rate"/&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="RateMaximum"/&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Height"/&gt;
                          &lt;/MultiBinding&gt;
                      &lt;/Canvas.Bottom&gt;
                  &lt;/Label&gt;
                  &lt;Line X1="0" X2="380" Stroke="Black"&gt;
                      &lt;Canvas.Bottom&gt;
                          &lt;MultiBinding Converter="{StaticResource JScript}" ConverterParameter="(values[2]*0.8)/values[1]*values[0]"&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Rate"/&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="RateMaximum"/&gt;
                              &lt;Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Height"/&gt;
                          &lt;/MultiBinding&gt;
                      &lt;/Canvas.Bottom&gt;
                  &lt;/Line&gt;
              &lt;/Canvas&gt;
          &lt;/ControlTemplate&gt;
      &lt;/RangeBase.Resources&gt;
  &lt;/rb:RateBase&gt;
  </code></pre>