zoukankan      html  css  js  c++  java
  • 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"];
    
                }
    

      

  • 相关阅读:
    QT visual stuido 集成插件不能打开ui文件的解决方法(去掉xml的UTF8标记)
    就异地协作办公来说, 360的体验完爆他们——360书生企业云盘 来了
    MVC 4
    Mvc的多层架构
    代码生成器
    js理解
    我(webabcd)的文章索引
    多个视图结果显示于一个共用预览视图内
    .NET源码
    Using Ninject in a Web Application
  • 原文地址:https://www.cnblogs.com/m7777/p/4477627.html
Copyright © 2011-2022 走看看