title: WPF Animation crash on collapsed element but not on hidden element
body: <p>Why does animation fail on collapsed controls and not on hidden controls?</p>
  <p>Concrete, in WPF I have a custom made checkbox with animation whereby the visibility is dynamically linked to the “setVisible” resource element (very simplified this looks like this).</p>
  <pre><code>&lt;local:MyCheckBox x:Name=&quot;checkNonVisual&quot; Visibility=&quot;{DynamicResource setVisible}&quot; /&gt;
  </code></pre>
  <p>In the code I set the value of the checkNonVisual to true, false or null and this triggers
  a small animation on the checkbox.</p>
  <p>This works when the visibility of the element / “setVisible” resource element is set to Visibility.Visible and Visibility.Hidden, but it crashes when the visibility is set to Visibility.Collapsed with the error show below.</p>
  <p>Can anyone explain me why the animation fails when the visibility is collapsed and why the animation does not fail when the visibility is hidden?</p>
  <p>If I want to continue using collapsed, how can I prevent the animation from running so it does not crash anymore?</p>
  <p><em>Extract of Stacktrace:</em></p>
  <blockquote>
  <p>System.InvalidOperationException was unhandled<br />
  Message='Check' name
  cannot be found in the name scope of
  'System.Windows.Controls.ControlTemplate'.<br />
  Source=PresentationFramework</p>
  <p>StackTrace:</p>
  <p>at System.Windows.Media.Animation.Storyboard.ResolveTargetName(String
  targetName, INameScope nameScope, DependencyObject element)</p>
  <p>at System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock
  currentClock, DependencyObject containingObject, INameScope nameScope,
  DependencyObject parentObject, String parentObjectName, PropertyPath
  parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary
  clockMappings, Int64 layer)</p>
  <p>[...]</p>
  <p>at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
  at System.Windows.Controls.Primitives.ToggleButton.OnChecked(RoutedEventArgs e)</p>
  <p>[...]</p>
  </blockquote>