zoukankan      html  css  js  c++  java
  • WPF动画基础小实例

    动画效果如下:

    源码如下:

    <UniformGrid Columns="2">
            <!--  DropShadowEffect阴影效果  -->
            <Grid>
                <Ellipse
                    x:Name="el"
                    Width="100"
                    Height="100"
                    Fill="#5c6bff">
                    <Ellipse.Effect>
                        <DropShadowEffect
                            x:Name="dse"
                            BlurRadius="5"
                            Direction="0"
                            ShadowDepth="5" />
                    </Ellipse.Effect>
                </Ellipse>
                <StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="ShadowDepth:" />
                        <TextBox Text="{Binding ElementName=dse, Path=ShadowDepth}" />
                        <TextBlock Text="默认值:5" />
                        <CheckBox Name="cbShadowDepth" IsChecked="True">
                            <CheckBox.Triggers>
                                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                                    <BeginStoryboard x:Name="daShadowDepth">
                                        <Storyboard>
                                            <DoubleAnimation
                                                AutoReverse="False"
                                                RepeatBehavior="Forever"
                                                Storyboard.TargetName="dse"
                                                Storyboard.TargetProperty="(DropShadowEffect.ShadowDepth)"
                                                From="5"
                                                To="50"
                                                Duration="0:0:15" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                                <EventTrigger RoutedEvent="CheckBox.Unchecked">
                                    <PauseStoryboard BeginStoryboardName="daShadowDepth" />
                                </EventTrigger>
                                <EventTrigger RoutedEvent="CheckBox.Checked">
                                    <ResumeStoryboard BeginStoryboardName="daShadowDepth" />
                                </EventTrigger>
                            </CheckBox.Triggers>
                        </CheckBox>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="BlurRadius:" />
                        <TextBox Text="{Binding ElementName=dse, Path=BlurRadius}" />
                        <TextBlock Text="默认值:5" />
                        <CheckBox Name="cbBlurRadius" IsChecked="True">
                            <CheckBox.Triggers>
                                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                                    <BeginStoryboard x:Name="daBlurRadius">
                                        <Storyboard>
                                            <DoubleAnimation
                                                AutoReverse="False"
                                                RepeatBehavior="Forever"
                                                Storyboard.TargetName="dse"
                                                Storyboard.TargetProperty="(DropShadowEffect.BlurRadius)"
                                                From="5"
                                                To="50"
                                                Duration="0:0:15" />
    
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                                <EventTrigger RoutedEvent="CheckBox.Unchecked">
                                    <PauseStoryboard BeginStoryboardName="daBlurRadius" />
                                </EventTrigger>
                                <EventTrigger RoutedEvent="CheckBox.Checked">
                                    <ResumeStoryboard BeginStoryboardName="daBlurRadius" />
                                </EventTrigger>
                            </CheckBox.Triggers>
                        </CheckBox>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Direction:" />
                        <TextBox Text="{Binding ElementName=dse, Path=Direction}" />
                        <TextBlock Width="150" Text="默认值:0,取值范围0-360" />
                        <CheckBox Name="cbDirection" IsChecked="True">
                            <CheckBox.Triggers>
                                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                                    <BeginStoryboard x:Name="daDirection">
                                        <Storyboard>
                                            <DoubleAnimation
                                                AutoReverse="False"
                                                RepeatBehavior="Forever"
                                                Storyboard.TargetName="dse"
                                                Storyboard.TargetProperty="(DropShadowEffect.Direction)"
                                                From="0"
                                                To="360"
                                                Duration="0:0:15" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                                <EventTrigger RoutedEvent="CheckBox.Unchecked">
                                    <PauseStoryboard BeginStoryboardName="daDirection" />
                                </EventTrigger>
                                <EventTrigger RoutedEvent="CheckBox.Checked">
                                    <ResumeStoryboard BeginStoryboardName="daDirection" />
                                </EventTrigger>
                            </CheckBox.Triggers>
                        </CheckBox>
                    </StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Color:" />
                        <TextBox Text="{Binding ElementName=dse, Path=Color}" />
                        <TextBlock Text="默认值:黑色" />
                    </StackPanel>
                </StackPanel>
            </Grid>
            <!--  BlurEffect模糊效果  -->
            <Grid>
                <Ellipse
                    x:Name="el2"
                    Width="100"
                    Height="100"
                    Fill="#5c6bff">
                    <Ellipse.Effect>
                        <BlurEffect x:Name="dse2" Radius="5" />
                    </Ellipse.Effect>
                </Ellipse>
                <StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="Radius:" />
                        <TextBox Text="{Binding ElementName=dse2, Path=Radius}" />
                        <TextBlock Text="默认值:5" />
                    </StackPanel>
                </StackPanel>
            </Grid>
        </UniformGrid>
  • 相关阅读:
    一个先进的App框架:使用Ionic创建一个简单的APP
    Hexo NexT 博客本地搭建指南
    Spring Boot 2.0 入门指南
    1. 初识 Lucene
    Spring Framework 简介
    电脑软件推荐安装列表
    PHP 环境搭建篇
    C++ STL 容器之栈的使用
    0x02 译文:Windows桌面应用Win32第一个程序
    反射?切面?怎样对公共参数及行为进行封装
  • 原文地址:https://www.cnblogs.com/kuangxiangnice/p/13559725.html
Copyright © 2011-2022 走看看