小编Ter*_*mas的帖子

从动画完成事件中获取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);
Run Code Online (Sandbox Code Playgroud)

这是我完成的活动,我希望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.

    }
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

c# wpf animation casting uielement

4
推荐指数
1
解决办法
2212
查看次数

标签 统计

animation ×1

c# ×1

casting ×1

uielement ×1

wpf ×1