2010-11-13 115 views
4

我試圖做從頁面導航離開時的動畫,但我得到這個錯誤:Windows Phone 7的導航動畫

指定對象上無法解析TargetProperty(UIElement.RenderTransform)(CompositeTransform.TranslateX)。 。

我複製了一本書中的代碼,並且測試了本書的示例代碼並且它可以工作,但是我無法在我的應用程序中使用它。有任何想法嗎?這是我的代碼:

XAML:

<phone:PhoneApplicationPage.Resources> 
     <Storyboard x:Name="HidePage" Completed="HidePage_Completed"> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="phoneApplicationPage"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:1" Value="-480"/> 
      </DoubleAnimationUsingKeyFrames> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="phoneApplicationPage"> 
       <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
       <EasingDoubleKeyFrame KeyTime="0:0:1" Value="-800"/> 
      </DoubleAnimationUsingKeyFrames> 
     </Storyboard> 
<phone:PhoneApplicationPage.Resources> 

C#

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) 
{ 
    base.OnNavigatingFrom(e); 

    if (this.UriToNavigateTo == null) 
    { 
     e.Cancel = true; 
     UriToNavigateTo = e.Uri; 
     this.HidePage.Begin(); 
    } 
    else 
    { 
     UriToNavigateTo = null; 
    } 
} 

謝謝!

+0

xaml不見了 – 2010-11-13 01:17:15

+0

@lukas它現在在那裏,謝謝 – Carlo 2010-11-13 08:09:59

回答

3

您忘記設置CompositeTransform對象,該對象定義了您正在使用的轉換類型。

<phone:PhoneApplicationPage.RenderTransform> 
    <CompositeTransform/> 
</phone:PhoneApplicationPage.RenderTransform> 
+0

工作,謝謝! – Carlo 2010-11-15 21:35:32

6

Silverlight工具包http://silverlight.codeplex.com/現在包含使用TransitionFrame控件的Windows Phone 7頁面的動畫。你可以閱讀更多關於它在這裏:http://blogs.msdn.com/b/delay/archive/2010/11/02/mo-controls-mo-controls-mo-controls-announcing-the-second-release-of-the-silverlight-for-windows-phone-toolkit.aspx

基本上,它的工作原理是您的RootFrame設置在App.xaml.cs一個TransitionFrame:

RootFrame = new TransitionFrame();

,然後設置導航轉變爲每個頁面:

<toolkit:TransitionService.NavigationInTransition> 
    <toolkit:NavigationInTransition> 
     <toolkit:NavigationInTransition.Backward> 
      <toolkit:TurnstileTransition Mode="BackwardIn"/> 
     </toolkit:NavigationInTransition.Backward> 
     <toolkit:NavigationInTransition.Forward> 
      <toolkit:TurnstileTransition Mode="ForwardIn"/> 
     </toolkit:NavigationInTransition.Forward> 
    </toolkit:NavigationInTransition> 
</toolkit:TransitionService.NavigationInTransition> 
<toolkit:TransitionService.NavigationOutTransition> 
    <toolkit:NavigationOutTransition> 
     <toolkit:NavigationOutTransition.Backward> 
      <toolkit:TurnstileTransition Mode="BackwardOut"/> 
     </toolkit:NavigationOutTransition.Backward> 
     <toolkit:NavigationOutTransition.Forward> 
      <toolkit:TurnstileTransition Mode="ForwardOut"/> 
     </toolkit:NavigationOutTransition.Forward> 
    </toolkit:NavigationOutTransition> 
</toolkit:TransitionService.NavigationOutTransition>
+0

肯定會檢查出來。謝謝(你的)信息! – Carlo 2010-11-15 21:34:58

+0

我試過了,但它在模擬器中沒有任何效果。 – 2011-08-26 03:16:20