开发者

How can i know if switching to a particular VisualState is over or not?

How can i get notified when switching to a particular VisualState is complete or not?

Example. VisualStateManager.GoToState(this, "UnloadState", true);

In above case i want to get notified when switched to UnloadedState is开发者_JS百科 completed.

Thanks in advance :)


If this is in a UserControl then its quite straight-forward, you can simply add a completed event handler to the StoryBoard associated with the state:-

<VisualState x:Name="UnloadState">
   <Storyboard Completed="UnloadState_Completed">

Then in code:-

 void UnloadState_Completed(object sender, EventArgs e)
 {
    // Do stuff when complete
 }

However in a templated control things are a little more complicated. You won't know whether the template even has such a state and you can't wire up with Xaml. However in OnApplyTemplate you should be able to find the VisualState with FindName then you can attach the event handler in code. You should hold the VisualState object in a field so that you can handle detaching the event handler correctly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜