【求助】用WPF做了一个动画演示,要怎么改进?

问题描述

我的问题在下面,其它可以改进的地方也请大家不吝赐教,新手不太懂啊XAML代码:Windowx:Class="WpfApplication4.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"Title="动画演示"Height="350"Width="525"><GridBackground="White"><TabControlHorizontalAlignment="Left"Height="100"Margin="27,196,0,0"VerticalAlignment="Top"Width="464"SelectionChanged="TabControl_SelectionChanged"><TabItemHeader="图形"RenderTransformOrigin="2.37,0.493"IsSelected="True"><GridBackground="#00000000"><TextBlockHorizontalAlignment="Left"Height="22"Margin="10,6,0,0"TextWrapping="Wrap"Text="形状:"VerticalAlignment="Top"Width="42"/><ComboBoxx:Name="shape"HorizontalAlignment="Left"Margin="57,6,0,0"VerticalAlignment="Top"Width="120"RenderTransformOrigin="0.517,0.091"SelectionChanged="shape_SelectionChanged"><ComboBoxItemContent="正方形"/><ComboBoxItemContent="圆形"/></ComboBox><TextBlockHorizontalAlignment="Left"Margin="10,36,0,0"TextWrapping="Wrap"Text="颜色:"VerticalAlignment="Top"Height="22"/><ComboBoxx:Name="color"HorizontalAlignment="Left"Margin="57,36,0,0"VerticalAlignment="Top"Width="120"SelectionChanged="color_SelectionChanged"><ComboBoxItemContent="红色"/><ComboBoxItemContent="黄色"/><ComboBoxItemContent="蓝色"/></ComboBox></Grid></TabItem><TabItemHeader="变换"><GridBackground="#00000000"><TextBlockHorizontalAlignment="Left"Margin="10,10,0,0"TextWrapping="Wrap"VerticalAlignment="Top"Text="缩放:"Height="20"/><TextBlockHorizontalAlignment="Left"Margin="10,42,0,0"TextWrapping="Wrap"Text="旋转:"VerticalAlignment="Top"/><TextBlockHorizontalAlignment="Left"Margin="206,42,0,0"TextWrapping="Wrap"VerticalAlignment="Top"Text="(顺时针方向)"/><TextBlockHorizontalAlignment="Left"Margin="249,10,0,0"TextWrapping="Wrap"Text="倾斜:"VerticalAlignment="Top"RenderTransformOrigin="1.741,0.875"/><Sliderx:Name="Slider1"HorizontalAlignment="Left"Margin="52,8,0,0"VerticalAlignment="Top"Width="149"Maximum="2"TickFrequency="0.1"TickPlacement="BottomRight"Value="1"/><Sliderx:Name="Slider2"HorizontalAlignment="Left"Margin="52,42,0,0"VerticalAlignment="Top"RenderTransformOrigin="-1.333,-1.6"Width="149"Minimum="-360"Maximum="360"TickPlacement="BottomRight"TickFrequency="10"/><Sliderx:Name="Slider3"HorizontalAlignment="Left"Margin="290,10,0,0"VerticalAlignment="Top"Width="139"Maximum="89"TickFrequency="5"TickPlacement="BottomRight"Minimum="-89"/><ButtonContent="重置"HorizontalAlignment="Left"Margin="354,42,0,0"VerticalAlignment="Top"Width="75"Visibility="Collapsed"/></Grid></TabItem><TabItemHeader="运动"><GridBackground="#00000000"><TextBlockHorizontalAlignment="Left"Margin="10,10,0,0"TextWrapping="Wrap"Text="方式:"VerticalAlignment="Top"/><ComboBoxHorizontalAlignment="Left"Margin="51,10,0,0"VerticalAlignment="Top"Width="120"SelectionChanged="ComboBox_SelectionChanged"><ComboBoxItemContent="弹跳"/></ComboBox><Sliderx:Name="slider4"IsSnapToTickEnabled="True"HorizontalAlignment="Left"Margin="293,10,0,0"VerticalAlignment="Top"RenderTransformOrigin="-4.917,0.5"Width="129"TickPlacement="BottomRight"Maximum="5"TickFrequency="0.5"SmallChange="1"Minimum="1"/><TextBlockHorizontalAlignment="Left"Margin="250,10,0,0"TextWrapping="Wrap"Text="速度:"VerticalAlignment="Top"/><TextBlockText="{BindingElementName=slider4,Path=Minimum}"HorizontalAlignment="Left"Margin="293,32,0,0"TextWrapping="Wrap"VerticalAlignment="Top"RenderTransformOrigin="-0.036,-0.688"/><TextBlockText="{BindingElementName=slider4,Path=Value}"HorizontalAlignment="Left"Margin="355,32,0,0"TextWrapping="Wrap"VerticalAlignment="Top"/><TextBlockText="{BindingElementName=slider4,Path=Maximum}"HorizontalAlignment="Left"Margin="415,32,0,0"TextWrapping="Wrap"VerticalAlignment="Top"/></Grid></TabItem></TabControl><CanvasHorizontalAlignment="Left"Height="181"Margin="27,10,0,0"VerticalAlignment="Top"Width="464"Background="#FF7AF9FF"Opacity="0.5"><Rectanglex:Name="square"Fill="White"Height="88"Canvas.Left="188"Canvas.Top="46.5"Width="88"Visibility="Collapsed"><Rectangle.RenderTransform><TransformGroup><ScaleTransformScaleX="{BindingElementName=Slider1,Path=Value,Mode=OneWay}"ScaleY="{BindingElementName=Slider1,Path=Value,Mode=OneWay}"/><SkewTransformAngleX="{BindingElementName=Slider3,Path=Value,Mode=OneWay}"/><RotateTransformAngle="{BindingElementName=Slider2,Path=Value,Mode=OneWay}"/><TranslateTransformx:Name="square1"/></TransformGroup></Rectangle.RenderTransform></Rectangle><Ellipsex:Name="circle"Fill="White"Height="88"Canvas.Left="188"Canvas.Top="46.5"Width="88"RenderTransformOrigin="0.5,0.5"Visibility="Collapsed"><Ellipse.RenderTransform><TransformGroup><ScaleTransformScaleX="{BindingElementName=Slider1,Path=Value,Mode=OneWay}"ScaleY="{BindingElementName=Slider1,Path=Value,Mode=OneWay}"/><SkewTransformAngleX="{BindingElementName=Slider3,Path=Value,Mode=OneWay}"/><RotateTransformAngle="{BindingElementName=Slider2,Path=Value,Mode=OneWay}"/><TranslateTransformx:Name="circle1"/></TransformGroup></Ellipse.RenderTransform></Ellipse></Canvas></Grid></Window>

解决方案

本帖最后由 zytbbkk 于 2015-04-27 23:03:36 编辑
解决方案二:
C#代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Navigation;usingSystem.Windows.Shapes;usingSystem.Windows.Media.Animation;namespaceWpfApplication4{///<summary>///MainWindow.xaml的交互逻辑///</summary>publicpartialclassMainWindow:Window{publicMainWindow(){InitializeComponent();}privatevoidTabControl_SelectionChanged(objectsender,SelectionChangedEventArgse){if(e.SourceisTabControl){}}privatevoidshape_SelectionChanged(objectsender,SelectionChangedEventArgse){stringshape=null;foreach(ComboBoxItemitemine.AddedItems){shape=item.Content.ToString();break;}switch(shape){case"正方形":square.Visibility=System.Windows.Visibility.Visible;circle.Visibility=System.Windows.Visibility.Collapsed;break;case"长方形":square.Visibility=System.Windows.Visibility.Collapsed;circle.Visibility=System.Windows.Visibility.Collapsed;break;case"圆形":square.Visibility=System.Windows.Visibility.Collapsed;circle.Visibility=System.Windows.Visibility.Visible;break;}}privatevoidcolor_SelectionChanged(objectsender,SelectionChangedEventArgse){stringcolor=null;foreach(ComboBoxItemitemine.AddedItems){color=item.Content.ToString();break;}switch(color){case"白色":square.Fill=newSolidColorBrush(Colors.White);circle.Fill=newSolidColorBrush(Colors.White);break;case"黑色":square.Fill=newSolidColorBrush(Colors.Black);circle.Fill=newSolidColorBrush(Colors.Black);break;case"红色":square.Fill=newSolidColorBrush(Colors.Red);circle.Fill=newSolidColorBrush(Colors.Red);break;case"黄色":square.Fill=newSolidColorBrush(Colors.Yellow);circle.Fill=newSolidColorBrush(Colors.Yellow);break;case"蓝色":square.Fill=newSolidColorBrush(Colors.Blue);circle.Fill=newSolidColorBrush(Colors.Blue);break;case"绿色":square.Fill=newSolidColorBrush(Colors.Green);circle.Fill=newSolidColorBrush(Colors.Green);break;}}privatevoidComboBox_SelectionChanged(objectsender,SelectionChangedEventArgse){stringmethod=null;foreach(ComboBoxItemitemine.AddedItems){method=item.Content.ToString();break;}switch(method){case"弹跳":DoubleAnimationdaX=newDoubleAnimation();DoubleAnimationdaY=newDoubleAnimation();BounceEasebe=newBounceEase();be.Bounces=2;be.Bounciness=3;daY.EasingFunction=be;daX.From=0D;daY.From=0D;daX.To=188;daY.To=46.5;Durationduration1=newDuration(TimeSpan.FromSeconds(1));daX.Duration=duration1;daY.Duration=duration1;this.square1.BeginAnimation(TranslateTransform.XProperty,daX);this.square1.BeginAnimation(TranslateTransform.YProperty,daY);this.circle1.BeginAnimation(TranslateTransform.XProperty,daX);this.circle1.BeginAnimation(TranslateTransform.YProperty,daY);break;case"水平平移":Randomr=newRandom();daX=null;daY=null;daX.To=100;daY.To=100;Durationduration2=newDuration(TimeSpan.FromSeconds(1));daX.Duration=duration2;daY.Duration=duration2;this.square1.BeginAnimation(TranslateTransform.XProperty,daX);this.square1.BeginAnimation(TranslateTransform.YProperty,daY);this.circle1.BeginAnimation(TranslateTransform.XProperty,daX);this.circle1.BeginAnimation(TranslateTransform.YProperty,daY);break;}}}}
解决方案三:
1.选完形状之后,如果调整了缩放那些,再选其他形状也是显示调整后的,怎样才能使缩放那些在选择形状后可以恢复初始值,或者怎么加一个重置按钮?2.弹跳那个动画怎么设置图形的初始位置在左上角?
解决方案四:
3.和1一样,再次选择形状后,它就不会再弹跳了,要怎么办?4.水平平移没有用是怎么回事?5.怎么用slider调整动画的速度?

时间: 2024-08-02 02:44:39

【求助】用WPF做了一个动画演示,要怎么改进?的相关文章

我用c#的wpf做了一个等待的窗口,等待窗口想定位到父窗口的中间,总是计算不出位置

问题描述 我用wpf做了个等待窗口,而且在线程启动的此窗口(此处安全及规范都已处理),因父窗口是winform做的,所以WindowStaruptLoacation=父窗口的中间,并不好用,所以无奈只得自己计算父窗口坐标,并设置wpf做的等待窗口的坐标位置,可是总是定位不准确,我已经将代码简化了下,如下wwd.Top=f.Location.Y;//wwd就是wpf做的等待窗口,f既是父窗口wwd.Left=f.Location.X;wwd.ShowDialog(); 我发现,随着父窗口的移动,w

【初学求助】我做了一个验证登录的东西但是无论怎么输入帐号密码都显示错误

问题描述 如题求助 解决方案 解决方案二:一样的代码前几分钟运行都是对的后面就不知道怎么不行了解决方案三:学会调试先解决方案四:sql建议selectpassword,能输出下看看,不过既然你说一样的代码之前是对的后来错了,一般是数据库的问题,应该是数据库动了什么,你最好把错误也贴上来解决方案五:撸主1.打开visualstudio2.F5,打断点,拿到运行时sql变量的值,去数据库执行下,对照下数据库的值和你输入的是否一致或者使用sqlprofilers监控下,单击登录按钮后,提交到数据库的s

请求大神-Windows 手写板报错,wpf做的

问题描述 Windows 手写板报错,wpf做的 用wpf做了一个手写板,有的windows操作系统不支持,报错:the ink recognizer could not be loaded(墨水系统无法加载),如果解决? 解决方案 windows控制面板-添加删除windows组件,ink支持勾选下

求助,做了一个计算器,想在FORM2里面显示计算记录

问题描述 求助,做了一个计算器,想在FORM2里面显示计算记录(序号.结算结果等等) 解决方案 解决方案二:LZ是遇到了什么问题?把代码贴来看下解决方案三:引用1楼lyq8376的回复: LZ是遇到了什么问题?把代码贴来看下 刚刚学,只完成了一个计算器.完全不会弄FORM2页做记录啊解决方案四:首先你要考虑将计算结果存储在什么地方.数据集还是文本,form2显示结果列表就可以了,在form1中控制form2的显示解决方案五:楼主在使用计算功能的时候应该是看不到Form2的,所以这些记录就要存起来

音乐播放-求助,在做音乐网站遇到的一个难题,求各路好心人支招

问题描述 求助,在做音乐网站遇到的一个难题,求各路好心人支招 a页面是用datalist做的一个页面有图片跟歌曲名两项内容,b页面是播放页面.如何点击a页面的歌曲名然后跳到b页面播放对应ID的数据库中的歌曲.. 解决方案 那么你的问题在哪里呢? 解决方案二: 用GET或POST都可以解决这个问题. 解决方案三: a页面在图片上做个超链接,点击后将ID发给B页面B页面再根据ID到库中检索歌曲位置,将歌曲加载到b中的播放器中. 解决方案四: 点击a页面的歌曲名的时候能获取到 歌曲对应的Id, 传到b

for语句-c#winform做一个动画()来监视for循环

问题描述 c#winform做一个动画()来监视for循环 类似看视频加载时的加载圈,当for执行的时候开始转动 当for语句结束时 停止转动 能不能做?求大神解惑?怎么做,求资料方法链接 解决方案 在for循环开始前加上 this.Cursor = Cursors.WaitCursor; 在For循环最后加上 this.Cursor = Cursors.Default; 如果是win7以上,会显示滚动的圈,xp以前是沙漏. 解决方案二: 如果不要鼠标效果,就自己做一个panel啥的显示,完了隐

求助:WPF调用一个已有的OpenGL程序,使用哪种方法好呢?

问题描述 现在已有一个使用OpenGL编写的树木建模程序,我需要用WPF做界面,对其进行调用.不知道使用什么方法比较合适?将C++程序封装成动态链接库然后调用,还是使用SharpGL,或是别的什么方法?求指点! 解决方案

WPF 做一个声音开关按钮 要求不同状态下按钮的背景图片不同

问题描述 目前在用WPF做一系统,现在要添加声音开关按钮,要求按钮在开关不同的状态下,按钮的背景图片不一样,大神们,怎么实现这个功能呢? 解决方案 解决方案二:定义一个bool类型的变量,默认是false,第一次的时候为false第二次为true,当为true的时候切换背景图片,这是我之前弄过的参考下privatevoidbtn_Click(objectsender,RoutedEventArgse){if(show==false){bt.Visibility=Visibility.Visibl

识别-[求助]如何做一个智能琴谱翻页应用。

问题描述 [求助]如何做一个智能琴谱翻页应用. 现在的难题在于--如何识别琴谱并析出琴谱中的音频段! 想请问各位,有没有类似的开发包? 我查过关于乐谱的OCR,但它好像只是识别和分割琴谱.具体不知道它怎么应用,不知道能不能将分割出来的琴谱相应地分析出音频? 很紧急,在这求助各位大大!!!先谢过. 解决方案 http://www.docin.com/p-425157464.html