开发者

What is the behavior of a WPF 4 ControlStoryboardAction trigger?

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 condit开发者_开发问答ion 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜