WinRT Xaml故事板

WinRT Xaml故事板,xaml,animation,windows-8,microsoft-metro,winrt-xaml,Xaml,Animation,Windows 8,Microsoft Metro,Winrt Xaml,我在我的书中写了这个故事板,但是每当我做一个游戏的时候;从C#文件看,什么也没发生。有人能告诉我下面的代码有什么问题吗 <Storyboard x:Name="SwapImages" > <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Width)" Storyboard.TargetName="Image" > <EasingD

我在我的书中写了这个故事板,但是每当我做一个游戏的时候;从C#文件看,什么也没发生。有人能告诉我下面的代码有什么问题吗

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

赖特
左边

我认为您无法设置对齐属性的动画(根据此问题),您可以尝试按照链接问题中的注释进行操作,然后将两幅图像放在画布中,然后从代码后面操纵x和y坐标,这是我在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();
    }
}
公共密封部分类主页面:第页
{
公共主页()
{
this.InitializeComponent();
}
/// 
///当此页面即将显示在框架中时调用。
/// 
///描述如何访问此页的事件数据。参数
///属性通常用于配置页面。
受保护的异步重写无效OnNavigatedTo(NavigationEventArgs e)
{
}
私有无效图像2_加载_1(对象发送方,路由目标e)
{
SwapImages.Begin();
}
}
它工作得很好唯一的一点是我编写了
SwapImages.Begin()方法,该事件在元素加载到屏幕上后激发


另一件您可能会弄错的事情是,设置路线动画并不意味着您将获得从左到右的平滑过渡。对齐始终相对于父容器,并且可以有很少的值集。因此,如果您想要平滑过渡,请尝试为画布X、Y等其他属性设置动画

是否尝试将FluidMoveBehavior直接附加到对象?可能是一个更简单的选择。你能给我指一下在windows 8上工作的文档/演示吗?