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.     }  

 

你可能感兴趣的:(windows,实现,phone,7,立体旋转动画)