Did WPF storyboard end naturally, or was it interrupted?

92 Views Asked by At

Background: I am creating an application using eye tracking. To prevent buttons being activated inadvertently by a short glance, I wish to introduce a delay between the user's gaze landing on the button and the button being activated.

I have created an animation that colours the button left to right to give the user visual feedback, as shown below on the number '6' (ignore the red dots, they are tracking markers that won't show normally). If the user looks away before the timeout, the button is not activated; if their gaze is still on the button at the end of the timeout, the button is activated.

Don't have the reputation to post images; it's at https://i.stack.imgur.com/fu3j7.jpg.

As I am using the animation to provide visual feedback to the user, it seems sensible to me to trigger the button activation from the animation completion.

The animation is triggered as follows:

<Style.Triggers>
 <Trigger Property="**attached property providing gaze notification**" Value="True">
  <Trigger.EnterActions>
   <BeginStoryboard Storyboard="{StaticResource AnimateButton}" />
  </Trigger.EnterActions>
  <Trigger.ExitActions>
   <BeginStoryboard>
    **storyboard to return button to normal**
   </BeginStoryboard>
  </Trigger.ExitActions>
 </Trigger>
</Style.Triggers>

The storyboard is defined in the Window's resources, with a Completed event handler assigned. In the handler, I'm currently printing Debug.WriteLine(((AnimationClock)sender).CurrentTime);. Irrespective of whether the user looks away from the button immediately, or holds their gaze for long enough (currently 0.5s) to activate the button, the value printed is 00:00:00.5000000. Looking through other fields of the clock instance doesn't give any hints either.

So, after all that exposition, the question: is there a method of determining whether the animation ran to completion of its own accord, or whether it was interrupted by the storyboard kicked off by Trigger.ExitActions?

My alternative is to hook the attached property providing gaze notification for changes, start a timer for the same length of time as the animation, then check whether the button still has gaze after that time, but I would much prefer the animation-driven method if it's viable.

Thank you.

0

There are 0 best solutions below