从动画完成事件获取 UIElement
从我的代码隐藏中,我想在特定的 UIElement
上启动动画,当该动画结束时,我想对该 UIElement
进行一些其他处理。我无法弄清楚如何将作为动画完成事件的发送者收到的 AnimationClock
对象转换为执行动画的 UIElement
对象。
这是我用来构建和启动动画的代码:
DoubleAnimation FadeOutAnim = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(.5));
FadeOutAnim.Completed += new EventHandler(FadeOutAnim_Completed);
UIElement element = lstMessages.ItemContainerGenerator.ContainerFromItem(sender) as UIElement;
if(element != null)
element.BeginAnimation(UIElement.OpacityProperty, FadeOutAnim);
这是我的 Completed 事件,我想在其中再次访问 UIElement
。
void FadeOutAnim_Completed(object sender, EventArgs e)
{
UIElement animation = sender; //This is an AnimationClock and I can't seem to figure out how to get my UIElement back.
}
任何帮助将不胜感激。
From my codebehind I want to start an animation on a specific UIElement
, when that animation ends I would like to do some other processing on that UIElement
. I am having trouble figuring out how to convert the AnimationClock
object that I receive as the sender of an Animation Completed event into the UIElement
object that the animation was performed on.
Here is the code I use to build and start the animation:
DoubleAnimation FadeOutAnim = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(.5));
FadeOutAnim.Completed += new EventHandler(FadeOutAnim_Completed);
UIElement element = lstMessages.ItemContainerGenerator.ContainerFromItem(sender) as UIElement;
if(element != null)
element.BeginAnimation(UIElement.OpacityProperty, FadeOutAnim);
And here is my Completed event where I want access to the UIElement
again.
void FadeOutAnim_Completed(object sender, EventArgs e)
{
UIElement animation = sender; //This is an AnimationClock and I can't seem to figure out how to get my UIElement back.
}
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果处理程序无用(我无法找到一种方法来恢复动画元素),您可以引发另一个包含该信息的事件:
甚至更简单的是在委托中进行直接方法调用:
If the handler is useless (i for one cannot find a way to get the animated element back), you could just raise another event which does contain that information:
Even easier would be to make a direct method-call in the delegate: