title: Why is my WPF binding not working in state change?
body: <p>I have some items in a WrapPanel.  I want to be able to click on an item and have it expand to the full width of the wrap panel.  I tried doing this by creating two states, Expanded and Colapsed, in the control that is used for each item.  For the Expanded state, I bound the Width of the control to be equal to the ActualWidth of the WrapPanel.  </p>
  
  <p>When I didn't get the result I expected, I tried setting Expanded value to a specific number (instead of the the binding).  That is working.  The items toggle between the two Colapsed and Exapanded widths.  I still want to have the Expanded state be equal to the width of the WrapPanel though, not an arbitrary fixed width.  I know my binding works because if I just bind the Width property directly (not via visual states), the items in the WrapPanel match its width.</p>
  
  <p>Expanded state with Binding - Doesn't work:</p>
  
  <pre><code>&lt;VisualState x:Name="Expanded"&gt;
  &lt;Storyboard&gt;
      &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="JobMaster"&gt;
          &lt;EasingDoubleKeyFrame KeyTime="0"&gt;
              &lt;EasingDoubleKeyFrame.Value&gt;
                   &lt;Binding 
                     Path="ActualWidth"
                     RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type WrapPanel}}" /&gt;
              &lt;/EasingDoubleKeyFrame.Value&gt;
          &lt;/EasingDoubleKeyFrame&gt;
      &lt;/DoubleAnimationUsingKeyFrames&gt;
  &lt;/Storyboard&gt;
  </code></pre>
  
  <p></p>
  
  <p>Expanded State with hard coded value - Works</p>
  
  <pre><code>&lt;VisualState x:Name="Expanded"&gt;
  &lt;Storyboard&gt;
      &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="JobMaster"&gt;
          &lt;EasingDoubleKeyFrame KeyTime="0" Value="800" /&gt;
      &lt;/DoubleAnimationUsingKeyFrames&gt;
  &lt;/Storyboard&gt;
  </code></pre>
  
  <p></p>
  
  <p>Bind the control Width property directly works</p>
  
  <pre><code>&lt;UserControl.Width&gt;
         &lt;Binding 
         Path="ActualWidth"
         RelativeSource="{RelativeSource AncestorType={x:Type WrapPanel}}" /&gt;
  &lt;/UserControl.Width&gt;
  </code></pre>
  
  <p>So why doesn't the Binding in the state work or is there another way to do this?</p>