WPF 实现加速小火箭~

WPF开发者QQ群: 340500857

       由于微信群人数太多入群请添加小编微信号

 yanjinhuawechat 或 W_Feng_aiQ 入群

 需备注WPF开发者 

  PS:有更好的方式欢迎推荐。

01

代码如下

一、创建 SpeedRocketsExample.xaml 代码如下。

<Window x:Class="WPFDevelopers.Samples.ExampleViews.SpeedRocketsMini"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WPFDevelopers.Samples.ExampleViews"xmlns:sys="clr-namespace:System;assembly=mscorlib"mc:Ignorable="d" WindowStyle="None" ShowInTaskbar="False"WindowState="Maximized" Background="Transparent"ResizeMode="NoResize" AllowsTransparency="True"Height="450" Width="800" MaxHeight="{x:Static SystemParameters.MaximizedPrimaryScreenHeight}"><Window.Resources><local:ActualHeightConverters x:Key="actualHeightConverters"/></Window.Resources><Grid><Button Style="{StaticResource PrimaryButton}" Content="X" Width="60" Height="40" VerticalAlignment="Top" HorizontalAlignment="Right"Click="Button_Click"/><Grid VerticalAlignment="Bottom"HorizontalAlignment="Right"Margin="0,0,0,40"><Grid.Resources><Storyboard x:Key="StoryboardMouseDown"><DoubleAnimation Storyboard.TargetName="rotate_y" To="0" Duration="0:0:0"Storyboard.TargetProperty="Angle"/><DoubleAnimation Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"Storyboard.TargetName="PART_Viewport3D"Duration="0:0:2" From="0" To="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window},Mode=FindAncestor}, Path=ActualHeight,Converter={StaticResource actualHeightConverters}}" EasingFunction="{StaticResource BackEaseEaseInOut}"/><RectAnimation Storyboard.TargetProperty="(Ellipse.Clip).(RectangleGeometry.Rect)"Storyboard.TargetName="Ellipse3"BeginTime="0:0:.5" To="0,80,100,100"Duration="0:0:2" From="0,10,100,100" AutoReverse="True"></RectAnimation><StringAnimationUsingKeyFrames Storyboard.TargetName="TextBlock1" Storyboard.TargetProperty="Text"BeginTime="0:0:.5" AutoReverse="True"><DiscreteStringKeyFrame Value="90"   KeyTime="0:0:0"/><DiscreteStringKeyFrame Value="85"   KeyTime="0:0:.30" /><DiscreteStringKeyFrame Value="70"   KeyTime="0:0:1" /><DiscreteStringKeyFrame Value="40"   KeyTime="0:0:1.5" /><DiscreteStringKeyFrame Value="10"   KeyTime="0:0:2" /></StringAnimationUsingKeyFrames><DoubleAnimation Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"Storyboard.TargetName="PART_Viewport3D"Duration="0:0:0" BeginTime="0:0:2"To="0"/></Storyboard><Storyboard  x:Key="StoryboardMouseEnter"><DoubleAnimation Duration="00:00:.5" BeginTime="00:00:0"From="0"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)"To="1"/><DoubleAnimation Duration="00:00:.5" BeginTime="00:00:0"From="0"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleY)"To="1" /><DoubleAnimation Storyboard.TargetName="rotate_y" From="0" To="360"BeginTime="00:00:.5" Storyboard.TargetProperty="Angle"Duration="0:0:1.5" RepeatBehavior="Forever" /></Storyboard><Storyboard x:Key="StoryboardMouseLeave"><DoubleAnimation Duration="00:00:0" To="0" Storyboard.TargetProperty="Angle" Storyboard.TargetName="rotate_y" /><DoubleAnimation Duration="00:00:0" From="1"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleX)"To="0"/><DoubleAnimation Duration="00:00:0" From="1"Storyboard.TargetName="PART_Viewport3D"Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TransformGroup.Children)[1].(ScaleTransform.ScaleY)"To="0" /></Storyboard></Grid.Resources><Grid Height="100" Width="100" ToolTip="按下加速~喵 (゜-゜)つロ "><Ellipse  Fill="White" Stroke="#FFAEABAB" StrokeThickness="1"></Ellipse><Ellipse  Fill="#FF5F9E74" Margin="4"></Ellipse><Ellipse  Fill="#FF6BCF77" Margin="8" x:Name="Ellipse3"><Ellipse.Clip><RectangleGeometry Rect="0,10,100,100"></RectangleGeometry></Ellipse.Clip></Ellipse><WrapPanel  HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock Foreground="White"FontSize="30"FontWeight="Bold" FontFamily="Agency FB"Text="90"x:Name="TextBlock1"></TextBlock><TextBlock Foreground="White"FontSize="30"Text="%"FontWeight="Bold" FontFamily="Agency FB"></TextBlock></WrapPanel><Grid.Triggers><EventTrigger RoutedEvent="MouseDown"><BeginStoryboard Storyboard="{StaticResource StoryboardMouseDown}"/></EventTrigger><EventTrigger RoutedEvent="MouseEnter"><BeginStoryboard Storyboard="{StaticResource StoryboardMouseEnter}"/></EventTrigger><EventTrigger RoutedEvent="MouseLeave"><BeginStoryboard Storyboard="{StaticResource StoryboardMouseLeave}"/></EventTrigger></Grid.Triggers></Grid><!--<Ellipse Height="80" Width="80" x:Name="Ellipse1"StrokeThickness="2" Stroke="{StaticResource PrimaryNormalSolidColorBrush}"ToolTip="按下加速~喵 (゜-゜)つロ "><Ellipse.Fill><LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"><GradientStop Color="#FFF7D1A3"/><GradientStop Color="#FFF98C0C" Offset="1"/><GradientStop Color="#FFF49F39" Offset="0.5"/></LinearGradientBrush></Ellipse.Fill><Ellipse.Triggers><EventTrigger RoutedEvent="MouseDown"><BeginStoryboard Storyboard="{StaticResource StoryboardY}"/></EventTrigger><EventTrigger RoutedEvent="MouseEnter"><BeginStoryboard Storyboard="{StaticResource StoryboardAngleY}"/></EventTrigger><EventTrigger RoutedEvent="MouseLeave"><BeginStoryboard Storyboard="{StaticResource StoryboardNormal}"/></EventTrigger></Ellipse.Triggers></Ellipse>--><Viewport3D Width="60" Height="60"RenderTransformOrigin=".5,.5"x:Name="PART_Viewport3D"IsHitTestVisible="False"><Viewport3D.RenderTransform><TransformGroup><TranslateTransform Y="0"/><ScaleTransform ScaleX="0" ScaleY="0"/></TransformGroup></Viewport3D.RenderTransform><!--<Viewport3D.Triggers><EventTrigger RoutedEvent="Viewport3D.MouseDown"><BeginStoryboard><Storyboard><DoubleAnimation Storyboard.TargetName="rotate_y" 
To="0" Duration="0:0:0"
Storyboard.TargetProperty="Angle"/><DoubleAnimation Storyboard.TargetProperty="(Viewport3D.RenderTransform).(TranslateTransform.Y)"Duration="0:0:1"To="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window},Mode=FindAncestor}, Path=ActualHeight,Converter={StaticResource actualHeightConverters}}" EasingFunction="{StaticResource BackEaseEaseInOut}"/></Storyboard></BeginStoryboard></EventTrigger><EventTrigger RoutedEvent="Viewport3D.MouseEnter"><BeginStoryboard><Storyboard TargetProperty="Angle"><DoubleAnimation Storyboard.TargetName="rotate_y" From="0" To="360" Duration="0:0:1.5" RepeatBehavior="Forever" /></Storyboard></BeginStoryboard></EventTrigger><EventTrigger RoutedEvent="MouseLeave"><BeginStoryboard><Storyboard Storyboard.TargetProperty="Angle" Storyboard.TargetName="rotate_y"><DoubleAnimation Duration="00:00:0" To="0" /></Storyboard></BeginStoryboard></EventTrigger></Viewport3D.Triggers>--><Viewport3D.Camera><OrthographicCamera LookDirection="0,0,-50" Position="0,0,50" UpDirection="0,1,0"/></Viewport3D.Camera><Viewport3D.Children><ModelVisual3D><ModelVisual3D.Content><AmbientLight Color="Transparent"/></ModelVisual3D.Content></ModelVisual3D><ContainerUIElement3D><Viewport2DVisual3D><Viewport2DVisual3D.Geometry><MeshGeometry3D Positions="-1,1,1 -1,-1,1 1,-1,1 1,1,1" TriangleIndices="0 1 2 0 2 3" TextureCoordinates="0,0 0,1 1,1 1,0"/></Viewport2DVisual3D.Geometry><Viewport2DVisual3D.Material><DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/></Viewport2DVisual3D.Material><Image Source="/Images/SpeedRockets/飞机.png"/></Viewport2DVisual3D><Viewport2DVisual3D><Viewport2DVisual3D.Material><DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True"/></Viewport2DVisual3D.Material><Viewport2DVisual3D.Geometry><MeshGeometry3D Positions="1,1,1 1,-1,1 -1,-1,1 -1,1,1"
TextureCoordinates="0,0 0,1 1,1 1,0"
TriangleIndices="0 1 2 0 2 3"/></Viewport2DVisual3D.Geometry><Image Source="/Images/SpeedRockets/飞机.png"/></Viewport2DVisual3D><ContainerUIElement3D.Transform><Transform3DGroup><RotateTransform3D CenterX="0" CenterY="0" CenterZ="1"><RotateTransform3D.Rotation><AxisAngleRotation3D x:Name="rotate_y" Axis="0 1 0" /></RotateTransform3D.Rotation></RotateTransform3D></Transform3DGroup></ContainerUIElement3D.Transform></ContainerUIElement3D></Viewport3D.Children></Viewport3D></Grid></Grid>
</Window>

二、SnowCanvas.xamlSpeedRocketsExample.xaml.cs 代码如下

using System;
using System.Windows;
using System.Windows.Data;namespace WPFDevelopers.Samples.ExampleViews
{/// <summary>/// SpeedRocketsMini.xaml 的交互逻辑/// </summary>public partial class SpeedRocketsMini : Window{public SpeedRocketsMini(){InitializeComponent();}private void Button_Click(object sender, RoutedEventArgs e){Close();}}public class ActualHeightConverters : IValueConverter{public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){return 0 - (double)value;}public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){return null;}}
}

02


效果预览

鸣谢素材提供者 - 王路飞

源码地址如下

Github:https://github.com/WPFDevelopersOrg

Gitee:https://gitee.com/WPFDevelopersOrg

WPF开发者QQ群: 340500857 

Github:https://github.com/WPFDevelopersOrg

出处:https://www.cnblogs.com/yanjinhua

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

转载请著名作者 出处 https://github.com/WPFDevelopersOrg

07ce89f400158f827f7f3e76499f9f34.png

扫一扫关注我们,

3d0346b3cac5e2017d6ae0b33f0deca3.gif

更多知识早知道!

62b13cbcc25095e3b562c4b360f8881a.gif

点击阅读原文可跳转至源代码

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/293561.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第二十四天 多维数组

经过前面对一维数组和二维数组的学习&#xff0c;我们充分的掌握了数组的定义和使用&#xff0c;接下来我们该学习的是&#xff1a;多维数组。比较简单的方法&#xff0c;想要提高数组的维数只要在声明的时候在索引多加一个中括号即可。比如&#xff1a;我们要声明三维数组那么…

最懂男人心的内裤,戳100个洞透气,超舒服

▲ 点击查看有什么日用品&#xff0c;需要盆友们时不时就经常补货买买买的&#xff1f;除了家里的酱油、纸巾、沐浴露&#xff0c;还有一样hin重要&#xff0c;那就是内裤&#xff01;除了洗澡的空挡&#xff0c;内裤就一直穿在身上&#xff0c;可以说内裤是比女友还亲、比手机…

搬家到此,嘿嘿

希望能够把遇到的技术问题给记录起来&#xff0c;给我加油吧&#xff01; 之前一直在网易博客上记录&#xff0c;刚搬到此地&#xff0c;尽快习惯下来啦转载于:https://www.cnblogs.com/lwjlss/p/5682533.html

C++ throw:抛出自己的异常

throw 是C中的关键字&#xff0c;用来抛出异常。如果不使用 throw 关键字&#xff0c;try 就什么也捕获不到&#xff1b;上节提到的 at() 函数在内部也使用了 throw 关键字来抛出异常。throw 既可以用在标准库中&#xff0c;也可以用在自定义的函数中&#xff0c;抛出我们期望的…

git - svn 平滑到 git

1. 建立自己的git仓库&#xff0c;需要是空git仓库 2. checkout 你的 git仓库 3. svn忽略.git文件&#xff0c;忽略.git .gitignore 4. 把 .git文件拷到你的 svn仓库 5. git 上传文件 ————可以用&#xff0c;但是不符合我的情况———— 1. 所有需要用到的&#xff1a;git…

Logback也爆漏洞了,总结下最近log相关的几个漏洞

大家好&#xff0c;我是君哥&#xff0c;周末又要结束了。前些天 Apache Log4j2 接连报了几个重大漏洞&#xff0c;好在我们的系统使用的 logback&#xff0c;可当我们正庆幸的时候&#xff0c;logback 也爆出漏洞了。今天我们一起来看一下这几个漏洞。CVE-2021-42550先看一下官…

vim配置php语法高亮

安装vim之后&#xff0c;将php语法高亮插件 php.vim&#xff0c;放到/usr/share/vim/vimfiles/syntax 目录下 php语法高亮插件在这里下载&#xff1a;http://www.vim.org/scripts/script.php?script_id1571 然后配置vim配置文件 vimrc 在这里 /etc/vimrc ,增加一行 “s…

九月十月百度人搜,阿里巴巴,腾讯华为小米搜狗笔试面试八十题

九月十月百度人搜&#xff0c;阿里巴巴&#xff0c;腾讯华为小米搜狗笔试面试八十题 引言 自发表上一篇文章至今&#xff08;事实上&#xff0c;上篇文章更新了近3个月之久&#xff09;&#xff0c;blog已经停了3个多月&#xff0c;而在那之前&#xff0c;自开博以来的21个月每…

C++ exception类

语言本身或者标准库抛出的异常都是 exception 的子类&#xff0c;称为标准异常&#xff08;Standard Exception&#xff09;。你可以通过下面的语句来匹配所有标准异常&#xff1a; try{ //可能抛出异常的语句}catch(exception &e){ //处理异常的语句} 之所以使用引用…

拿了年终奖后,发现自己又拖后腿了?对不起,可能事实并没有那么糟糕...

全世界只有3.14 % 的人关注了爆炸吧知识不平凡的2020年早已过去了&#xff0c;打工人们已经跨过了2021年的门槛。2021年将会怎么样&#xff0c;那只有到2021年结束后我们才会知道。但我们的情绪常常毫无例外地会被“年终奖”这个关键词所扰动&#xff0c;无论在什么时候&#x…

JAVA-MyBatis ORM

MyBatis 的前身就是 iBatis 。是一个数据持久层(ORM)框架。 iBATIS一词来源于“internet”和“abatis”的组合&#xff0c;是一个基于Java的持久层框架。iBATIS提供的持久层框架包括SQL Maps和Data Access Objects&#xff08;DAO&#xff09;&#xff0c;同时还提供一个利用这…

Leetcode: Single Number

Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? Analysis: 需求里面要求O(N)时间以及无额外空间&…

如何使用 C# 压缩单个文件?

咨询区 user3362735我的项目有一个需求&#xff0c;需要对 文件夹 下的文件进行压缩&#xff0c;我用 ZipFile.CreateFromDirectory 方法发现并不能成功&#xff0c;但我对整个文件夹压缩是没有问题的&#xff0c;请问我该如何正确实现&#xff1f;回答区 John Koerner可以借助…

Android之mediarecorder中的方法以及工作流程的过程

嵌套、关联的类 class MediaRecorder.AudioEncoder 定义音频编码 class MediaRecorder.AudioSource 定义声音资源 interface MediaRecorder.OnErrorListener Interface definition for a callback to be invoked when an error occurs while recording. int…

杭电Problem 1872 稳定排序

稳定排序 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5200 Accepted Submission(s): 1988Problem Description大家都知道&#xff0c;快速排序是不稳定的排序方法。如果对于数组中出现的任意a[i],a[j](i<…

AMD and CMD are dead之KMD.js依赖可视化工具发布

使用 require("MyAapp.DepTree", function (DepTree) {DepTree(({renderTo: "holder",width: "820",height: "580",data: [{ "name": "System" },{ "name": "Util" },{ "name": &q…

WPF中的触发器(Trigger)

这节来讲一下WPF中的触发器——Trigger。触发器&#xff0c;是指在既定条件或者特殊场景下被触发&#xff0c;从而去执行一个操作。在WPF中&#xff0c;触发器可以分为以下几类&#xff1a;基本触发器(Trigger)&#xff1b;事件触发器(EventTrigger)&#xff1b;数据触发器(Dat…

uCOS:时钟节拍代码追踪

uCos中的时钟节拍可以基于软中断实现或者基于时钟节拍任务&#xff08;但是这个任务要给予很高的优先级&#xff09;对于STM32&#xff08;Cortex-M3&#xff09;来说这个就是SysTick中断0x0000003C当中断发生时调用OS_CPU_SysTickHandler函数&#xff0c;这样就提供了系统的时…

数学之美番外篇:平凡而又神奇的贝叶斯方法

概率论只不过是把常识用数学公式表达了出来。 ——拉普拉斯 记得读本科的时候&#xff0c;最喜欢到城里的计算机书店里面去闲逛&#xff0c;一逛就是好几个小时&#xff1b;有一次&#xff0c;在书店看到一本书&#xff0c;名叫贝叶斯方法。当时数学系的课程还没有学到概率统计…