2
votes

I have a question that's been bugging me for a while:

I have a lengthy IO operation which I invoke asynchronously, and I want my UI to show a blinking text to tell the users that the data is loading.

I have an IsLoading boolean property in my ViewModel, and I used a ControlStoryboardAction to kickoff the blinking animation, which is set to repeat forever. For my ControlStoryboardAction trigger, I configured a data trigger to see if IsLoading is true, and start my storyboard if true.

My problem is, when my IO operation returns, and I set IsLoading back to false, the animation continues to play. I thought once the trigger condition evaluated to false, it would stop the animation?

I then added a second ControlStoryboardAction to stop the animation if IsLoading evaluted to false, but this didn't have any effect. The animation continued to play after IsLoading was false.

Can anyone explain to me how trigger works in ControlStoryboardAction? In normal data triggers in WPF, once the condition evaluated to false, the property would be set back to its original state. It seems triggers in WPF actions don't work the same way?

1

1 Answers

0
votes

Generally speaking, a DataTrigger will put properties back to their previous value when the specified condition is no longer true.

The same is not true of actions, though. There's no way for the trigger to know what action would "undo" the effect of the triggered action, assuming that there is even such an action.

I think what you want to do is define another trigger on the opposite condition (e.g., using a boolean-not converter on IsLoading, adding an IsNotLoading property, etc.) that runs a "Stop" ControlStoryboardAction.