wpf获取模板化控件中的动画。

 

直接在在模版中用blend添加动画,默认会放在ControlTemplate 的 Resources下面,使用了多种方法都无法正确获取Storyboard。。

<ControlTemplate TargetType="{x:Type local:TWindow}">
                        <ControlTemplate .Resources>
                            <Storyboard x:Key="PromptMessage">
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="promptGrid">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                                    <DiscreteObjectKeyFrame KeyTime="0:0:1.5" Value="{x:Static Visibility.Collapsed}"/>
                                </ObjectAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="promptBorder">
                                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                                    <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.01"/>
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </ControlTemplate .Resources>
                    <Grid x:Name="PART_MainGrid" Margin="3">
    </Grid>
 </ControlTemplate>

  

将动画移到Grid的Resources下面,通过Grid来找到动画。代码如下。

 

<ControlTemplate TargetType="{x:Type local:TWindow}">
                    <Grid x:Name="PART_MainGrid" Margin="3">
                        <Grid.Resources>
                            <Storyboard x:Key="PromptMessage">
                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="promptGrid">
                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                                    <DiscreteObjectKeyFrame KeyTime="0:0:1.5" Value="{x:Static Visibility.Collapsed}"/>
                                </ObjectAnimationUsingKeyFrames>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="promptBorder">
                                    <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1"/>
                                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                                    <EasingDoubleKeyFrame KeyTime="0:0:1.5" Value="0.01"/>
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </Grid.Resources>
</Grid>
 </ControlTemplate>

  

          Grid  rootGrid = this.GetTemplateChild("PART_MainGrid") as Grid;
            if (rootGrid != null)
            {
              Storyboard PromptMessage = (Storyboard)rootGrid.Resources["PromptMessage"];

            }

  

 

转载于:https://www.cnblogs.com/m7777/p/4477627.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值