2012-12-20 91 views
0

我寫了這個故事板在我的每當我做一個SwapImages.Begin();從C#文件沒有任何反應。有人能告訴我什麼可能是錯誤的代碼在下面?WinRT Xaml StoryBoard

<Storyboard x:Name="SwapImages" > 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Width)" Storyboard.TargetName="Image" > 
      <EasingDoubleKeyFrame KeyTime="0" Value="300" /> 
      <EasingDoubleKeyFrame KeyTime="0:0:5" Value="0" /> 
     </DoubleAnimationUsingKeyFrames> 

     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Width)" Storyboard.TargetName="Image2" > 
      <EasingDoubleKeyFrame KeyTime="0" Value="0" /> 
      <EasingDoubleKeyFrame KeyTime="0:0:5" Value="300" /> 
     </DoubleAnimationUsingKeyFrames> 

     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.HorizontalAlignment)" Storyboard.TargetName="Image"> 
      <DiscreteObjectKeyFrame KeyTime="00:00:7"> 
       <DiscreteObjectKeyFrame.Value> 
        <HorizontalAlignment>Right</HorizontalAlignment> 
       </DiscreteObjectKeyFrame.Value> 
      </DiscreteObjectKeyFrame> 
     </ObjectAnimationUsingKeyFrames> 

     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.HorizontalAlignment)" Storyboard.TargetName="Image2"> 
      <DiscreteObjectKeyFrame KeyTime="00:00:7"> 
       <DiscreteObjectKeyFrame.Value> 
        <HorizontalAlignment>Left</HorizontalAlignment> 
       </DiscreteObjectKeyFrame.Value> 
      </DiscreteObjectKeyFrame> 
     </ObjectAnimationUsingKeyFrames> 
+0

您是否嘗試將FluidMoveBehavior直接附加到對象上?可能是一個更容易的選擇。 –

回答

0

我不認爲你可以動畫的取向性(根據這個問題here)你可以嘗試做什麼的鏈接問題的評論說,把你的兩個圖像在畫布上,然後操縱有X y代碼後面的代碼

0

這是我寫在MainPage.xaml中的代碼以及我的故事板,並且我確實得到了輸出。

<Page 
x:Class="TestApp.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:TestApp" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
xmlns:data="using:TestApp"> 
<Page.Resources> 
    <Storyboard x:Name="SwapImages" > 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Width)" Storyboard.TargetName="Image" > 
      <EasingDoubleKeyFrame KeyTime="0" Value="300" /> 
      <EasingDoubleKeyFrame KeyTime="0:0:5" Value="0" /> 
     </DoubleAnimationUsingKeyFrames> 

     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Width)" Storyboard.TargetName="Image2" > 
      <EasingDoubleKeyFrame KeyTime="0" Value="0" /> 
      <EasingDoubleKeyFrame KeyTime="0:0:5" Value="300" /> 
     </DoubleAnimationUsingKeyFrames> 

     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.HorizontalAlignment)" Storyboard.TargetName="Image"> 
      <DiscreteObjectKeyFrame KeyTime="00:00:7"> 
       <DiscreteObjectKeyFrame.Value> 
        <HorizontalAlignment>Right</HorizontalAlignment> 
       </DiscreteObjectKeyFrame.Value> 
      </DiscreteObjectKeyFrame> 
     </ObjectAnimationUsingKeyFrames> 

     <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.HorizontalAlignment)" Storyboard.TargetName="Image2"> 
      <DiscreteObjectKeyFrame KeyTime="00:00:7"> 
       <DiscreteObjectKeyFrame.Value> 
        <HorizontalAlignment>Left</HorizontalAlignment> 
       </DiscreteObjectKeyFrame.Value> 
      </DiscreteObjectKeyFrame> 
     </ObjectAnimationUsingKeyFrames> 
    </Storyboard> 
</Page.Resources> 
<Grid > 
    <Rectangle Fill="Red" Height="100" Margin="430,237,0,0" Stroke="Black" Name="Image" VerticalAlignment="Top" Width="100"/> 
    <Rectangle Fill="Green" Loaded="Image2_Loaded_1" Height="100" Margin="922,212,0,0" Stroke="Black" VerticalAlignment="Top" Width="100" Name="Image2"/> 
</Grid></Page> 

這裏的落後於上述XAML

public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
     this.InitializeComponent(); 

    } 

    /// <summary> 
    /// Invoked when this page is about to be displayed in a Frame. 
    /// </summary> 
    /// <param name="e">Event data that describes how this page was reached. The Parameter 
    /// property is typically used to configure the page.</param> 
    protected async override void OnNavigatedTo(NavigationEventArgs e) 
    { 

    } 

    private void Image2_Loaded_1(object sender, RoutedEventArgs e) 
    { 
     SwapImages.Begin(); 
    } 
} 

代碼它能正常工作唯一的是,我在元件裝入到屏幕上,之後被觸發加載的事件寫了SwapImages.Begin();方法。

另一件你可能會誤解的事實是動畫對齊並不意味着你會從左到右平滑過渡。對齊總是相對於父容器,並且可以具有幾組值。所以如果你想要一個平滑的過渡嘗試動畫像帆布X,Y等一些其他財產等。

+0

你能指點我的文檔/演示這個,在Windows 8上工作? – Samurai336