当ContentControl.Content改变动画开始 [英] Begin animation when ContentControl.Content is changed

查看:173
本文介绍了当ContentControl.Content改变动画开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图触发一个动画在内容控制,如按钮或ContentControl中改变其内容。我最初的想法是要做到这一点:

I'm trying to fire an animation when a content control such as Button or ContentControl changes its content. My initial thoughts were to do this:

        <ContentControl x:Name="ContentElement">
            <ContentControl.Style>
                <Style TargetType="ContentControl">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ContentControl">
                                <ContentPresenter x:Name="Content">
                                    <ContentPresenter.Triggers>
                                        <EventTrigger RoutedEvent="WHATGOESHERE">
                                            <BeginStoryboard Storyboard="{StaticResource MyAnimation}" Storyboard.TargetName="Content"/>
                                        </EventTrigger>
                                    </ContentPresenter.Triggers>
                                </ContentPresenter>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ContentControl.Style>

            <Button Content="Hello"/>
        </ContentControl>



但我不知道哪个事件触发时,ContentPresenter改变/更新。任何想法?

But I don't know which event fires when the ContentPresenter is changed/updated. Any ideas?

推荐答案

有没有CLR-事件ContentChanged(少得多的EventTriggers需要RoutedEvent)很可惜。然而,鉴于你处理一个自定义的控制,您可以覆盖的元数据内容属性,并提供控制范围之内自己的回调。

There is no CLR-event for ContentChanged (much less a RoutedEvent required for EventTriggers) unfortunately. However, given that you're dealing with a custom control, you can override the metadata for the Content property and provide your own callback within the control.

这可能是有关您正在寻找什么这里

This may be about what you're looking for here

显然,他创造了一个CLR事件从外部传播内容的变化;你也可以做同样只使用一个RoutedEvent来代替。

Obviously he's created a CLR-event to propagate content changes externally; you could also do the same just using a RoutedEvent instead.

在OverrideMetadata补充阅读的这里

Additional reading on OverrideMetadata here

这篇关于当ContentControl.Content改变动画开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆