2012-06-19 87 views
0

我希望停止使用DispatcherTimer來顯示動畫,因爲這是非常不可預測的。相反,我想開始使用Storyboard,因爲這顯然是動畫控制的最佳和最有效的方式。如何使用故事板

我試過尋找教程,但不幸的是,還沒有找到一個。

任何人都可以請告訴我從哪裏開始?例如,「在屏幕上移動圖像」,然後「在旋轉它們的同時移動許多圖像」。

回答

1

有大量的信息在那裏關於Windows Phone的7故事板動畫這裏有幾個環節:

http://msdn.microsoft.com/en-us/library/system.windows.media.animation.storyboard(v=vs.95).aspx

http://www.silverlight.net/learn/creating-ui/animation-and-easing/animations-(silverlight-quickstart

下面是一些代碼,讓你開始

這將動畫一個簡單的矩形,在屏幕上來回移動它。

<phone:PhoneApplicationPage 
    x:Class="PhoneApp1.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="Portrait" Orientation="Portrait" 
    shell:SystemTray.IsVisible="True"> 

    <Grid x:Name="LayoutRoot" Background="Transparent"> 
     <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
      <Rectangle x:Name="rect" Height="25" Width="25" Fill="Red" HorizontalAlignment="Left" VerticalAlignment="Top"> 
       <Rectangle.RenderTransform> 
        <TranslateTransform x:Name="transform" /> 
       </Rectangle.RenderTransform> 
       <Rectangle.Triggers> 
        <EventTrigger RoutedEvent="Rectangle.Loaded"> 
         <BeginStoryboard> 
          <Storyboard> 
           <DoubleAnimation 
            Storyboard.TargetName="transform" 
            Storyboard.TargetProperty="X" 
            From="0" To="100" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever" /> 
          </Storyboard> 
         </BeginStoryboard> 
        </EventTrigger> 
       </Rectangle.Triggers> 
      </Rectangle> 
     </Grid> 
    </Grid> 


</phone:PhoneApplicationPage> 
+0

我不是那種「高級」,只是簡單地消化存儲在MSDN網站上的信息。我必須主要看真實的代碼,分析和理解它。然後把它付諸實踐。你提供的第二個鏈接似乎非常好。我會檢查出來的。謝謝你,先生。 – Subby

+0

沒問題。請參閱我的編輯以獲取一個簡單的示例,幫助您開始。 – tjscience

+0

Windows Phone中沒有觸發器。代碼是來自WPF而不是Windows Phone。 –