Windows Phone 7 立体旋转动画的实现

简介:

Storyboard.TargetProperty表示获取或设置应进行动画处理的属性的名称。通过对Storyboard.TargetProperty属性的设置可以很简单地实现X轴、Y轴、Z轴的立体旋转效果。

Storyboard.TargetProperty="RotationX"表示沿X轴旋转

Storyboard.TargetProperty="RotationY"表示沿Y轴旋转

Storyboard.TargetProperty="RotationZ"表示沿Z轴旋转

下面是一个立体旋转的实例:

 

  

 


 
 
  1. <phone:PhoneApplicationPage   
  2.     x:Class="PerspectiveRotation.MainPage" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}" 
  11.     FontSize="{StaticResource PhoneFontSizeNormal}" 
  12.     Foreground="{StaticResource PhoneForegroundBrush}" 
  13.     SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" 
  14.     shell:SystemTray.IsVisible="True"> 
  15.       
  16.     <phone:PhoneApplicationPage.Resources> 
  17.         <Storyboard x:Name="rotateX"><!--沿X轴方向旋转的面板--> 
  18.             <DoubleAnimation Storyboard.TargetName="planeProjection" 
  19.                              Storyboard.TargetProperty="RotationX" 
  20.                              From="0" To="360" Duration="0:0:5" /> 
  21.         </Storyboard> 
  22.         <Storyboard x:Name="rotateY"><!--沿Y轴方向旋转的面板--> 
  23.             <DoubleAnimation Storyboard.TargetName="planeProjection" 
  24.                              Storyboard.TargetProperty="RotationY" 
  25.                              From="0" To="360" Duration="0:0:5" /> 
  26.         </Storyboard> 
  27.         <Storyboard x:Name="rotateZ"><!--沿Z轴方向旋转的面板--> 
  28.             <DoubleAnimation Storyboard.TargetName="planeProjection" 
  29.                              Storyboard.TargetProperty="RotationZ" 
  30.                              From="0" To="360" Duration="0:0:5" /> 
  31.         </Storyboard> 
  32.     </phone:PhoneApplicationPage.Resources> 
  33.  
  34.     <!--LayoutRoot is the root grid where all page content is placed--> 
  35.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  36.         <Grid.RowDefinitions> 
  37.             <RowDefinition Height="Auto"/> 
  38.             <RowDefinition Height="*"/> 
  39.         </Grid.RowDefinitions> 
  40.  
  41.         <!--TitlePanel contains the name of the application and page title--> 
  42.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
  43.             <TextBlock x:Name="ApplicationTitle" Text="立体旋转" Style="{StaticResource PhoneTextNormalStyle}"/> 
  44.         </StackPanel> 
  45.  
  46.         <!--ContentPanel - place additional content here--> 
  47.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
  48.             <Grid.RowDefinitions> 
  49.                 <RowDefinition Height="*" /> 
  50.                 <RowDefinition Height="Auto" /> 
  51.             </Grid.RowDefinitions> 
  52.               
  53.             <Grid.ColumnDefinitions> 
  54.                 <ColumnDefinition Width="*" /> 
  55.                 <ColumnDefinition Width="*" /> 
  56.                 <ColumnDefinition Width="*" /> 
  57.             </Grid.ColumnDefinitions> 
  58.               
  59.             <TextBlock Name="txtblk" 
  60.                        Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" 
  61.                        Text="Oh,My God" 
  62.                        FontSize="70" 
  63.                        Foreground="{StaticResource PhoneAccentBrush}" 
  64.                        HorizontalAlignment="Center" 
  65.                        VerticalAlignment="Center"> 
  66.                 <TextBlock.Projection> 
  67.                     <PlaneProjection x:Name="planeProjection" /> 
  68.                 </TextBlock.Projection> 
  69.             </TextBlock> 
  70.               
  71.             <Button Grid.Row="1" Grid.Column="0" 
  72.                     Content="旋转-X轴" 
  73.                     Click="RotateXClick" /> 
  74.               
  75.             <Button Grid.Row="1" Grid.Column="1" 
  76.                     Content="旋转-Y轴" 
  77.                     Click="RotateYClick" /> 
  78.               
  79.             <Button Grid.Row="1" Grid.Column="2" 
  80.                     Content="旋转-Z轴" 
  81.                     Click="RotateZClick" /> 
  82.         </Grid> 
  83.     </Grid> 
  84.  
  85. </phone:PhoneApplicationPage> 

 


 
 
  1. using System;  
  2. using System.Windows;  
  3. using Microsoft.Phone.Controls;  
  4.  
  5. namespace PerspectiveRotation  
  6. {  
  7.     public partial class MainPage : PhoneApplicationPage  
  8.     {  
  9.         public MainPage()  
  10.         {  
  11.             InitializeComponent();  
  12.         }  
  13.         //沿X轴旋转  
  14.         void RotateXClick(object sender, RoutedEventArgs args)  
  15.         {  
  16.             rotateX.Begin();  
  17.         }  
  18.         //沿Y轴旋转  
  19.         void RotateYClick(object sender, RoutedEventArgs args)  
  20.         {  
  21.             rotateY.Begin();  
  22.         }  
  23.         //沿Z轴旋转  
  24.         void RotateZClick(object sender, RoutedEventArgs args)  
  25.         {  
  26.             rotateZ.Begin();  
  27.         }  
  28.     }  

 


本文转自linzheng 51CTO博客,原文链接:http://blog.51cto.com/linzheng/1078708


相关文章
|
Java Windows
使用 windows bat 脚本命令一键实现快速配置JDK 环境变量
使用 windows bat 脚本命令一键实现快速配置JDK 环境变量
696 0
使用 windows bat 脚本命令一键实现快速配置JDK 环境变量
|
消息中间件 安全 API
C#实现操作Windows窗口句柄:SendMessage/PostMessage发送系统消息、事件和数据【窗口句柄总结之二】
SendMessage/PostMessage API 可以实现发送系统消息,这些消息可以定义为常见的鼠标或键盘事件、数据的发送等各种系统操作......
6015 1
C#实现操作Windows窗口句柄:SendMessage/PostMessage发送系统消息、事件和数据【窗口句柄总结之二】
|
7月前
|
Web App开发 数据可视化 JavaScript
动画墙纸:将视频、网页、游戏、模拟器变成windows墙纸——Lively Wallpaper
动画墙纸:将视频、网页、游戏、模拟器变成windows墙纸——Lively Wallpaper
126 0
|
API C# Windows
C#实现操作Windows窗口句柄:常用窗口句柄相关API、Winform中句柄属性和Process的MainWindowHandle问题【窗口句柄总结之三】
本篇主要介绍一些与窗口句柄相关的一些API,比如设置窗口状态、当前激活的窗口、窗口客户区的大小、鼠标位置、禁用控件等,以及介绍Winform中的句柄属性,便于直接获取控件或窗体句柄,以及不推荐...
3475 0
C#实现操作Windows窗口句柄:常用窗口句柄相关API、Winform中句柄属性和Process的MainWindowHandle问题【窗口句柄总结之三】
|
前端开发 Windows
HTML+CSS制作Windows启动加载动画
HTML+CSS制作Windows启动加载动画
|
Ubuntu 安全 Linux
【过关斩将般的一步步实现】windows本机通过xftp/xshell连接Ubuntu虚拟机服务器
【过关斩将般的一步步实现】windows本机通过xftp/xshell连接Ubuntu虚拟机服务器
1041 1
【过关斩将般的一步步实现】windows本机通过xftp/xshell连接Ubuntu虚拟机服务器
|
API C# Windows
C#实现操作Windows窗口句柄:遍历、查找窗体和控件【窗口句柄最全总结之一】
C#对Windows窗口或窗口句柄的操作,都是通过 P/Invoke Win32 API 实现的,DllImport引入Windows API操作窗口(句柄),可以实现枚举已打开的窗口、向窗口...
4206 0
C#实现操作Windows窗口句柄:遍历、查找窗体和控件【窗口句柄最全总结之一】
|
JSON Java API
C#winforms实现windows窗体人脸识别
C#winforms实现windows窗体人脸识别
353 0
|
Linux iOS开发 开发者
实现在windows、linux下上传ios app到App Store
实现在windows、linux下上传ios app到App Store
实现在windows、linux下上传ios app到App Store
|
JSON JavaScript 安全
基于Windows微信实现实时收发微信消息App
基于Windows微信实现实时收发微信消息App
1477 0