Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you set IsBusy to true in your button click handler you will see the animation does work. The problem is you are setting it to true before it has loaded so _layoutRoot and _storyboard are null and the animation never begins.</p> <pre><code>public class CustomBusyControl : Control { public CustomBusyControl() { DefaultStyleKey = typeof(CustomBusyControl); Loaded += (s,e) =&gt; ToggleBusy(this); } public static readonly DependencyProperty IsBusyProperty = DependencyProperty.Register("IsBusy", typeof(bool), typeof(CustomBusyControl), new PropertyMetadata(new PropertyChangedCallback(OnIsBusyChanged))); private static void OnIsBusyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { ToggleBusy(obj as CustomBusyControl); } private static void ToggleBusy(CustomBusyControl control) { if (control != null &amp;&amp; control._layoutRoot != null &amp;&amp; control._storyboard != null) { if ((bool)control.IsBusy) { control._layoutRoot.Visibility = Visibility.Visible; control._storyboard.Begin(); } else { control._layoutRoot.Visibility = Visibility.Collapsed; control._storyboard.Stop(); } } } private Canvas _layoutRoot; private Storyboard _storyboard; public override void OnApplyTemplate() { _layoutRoot = GetTemplateChild("LayoutRoot") as Canvas; Debug.Assert(_layoutRoot != null, "LayoutRoot is null"); _storyboard = GetTemplateChild("IndicatorStoryboard") as Storyboard; base.OnApplyTemplate(); } public bool IsBusy { get { return (bool)GetValue(IsBusyProperty); } set { SetValue(IsBusyProperty, value); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload