Windows Phone - 网格幻灯片动画

时间:2014-09-16 06:59:37

标签: c# animation windows-phone

我试图为整个网格做幻灯片动画,但有例外:"无法解析TargetName translateTransform。"怎么了?

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
    <Grid.RenderTransform>
        <TranslateTransform x:Name="translateTransform" X="500" />
    </Grid.RenderTransform>
    <Grid.Resources>
        <Storyboard x:Name="StoryBoard1">
            <DoubleAnimation Storyboard.TargetName="ContentPanel"
             Storyboard.TargetProperty="Opacity"
             From="0" To="1" Duration="0:0:1"
             />
            <DoubleAnimation Storyboard.TargetName="translateTransform"
             Storyboard.TargetProperty="X"
             From="500" To="200" Duration="0:0:1"/>
        </Storyboard>
    </Grid.Resources>
    <TextBlock x:Name="Txt2" Text="foo">
    </TextBlock>

1 个答案:

答案 0 :(得分:0)

您缺少x:来自Storyboard资源的密钥,所有资源都需要x:Key。我的VS2013说的是。

<Grid x:Name="ContentPanel" 
              Background="Purple"

              Grid.Row="1" Margin="12,0,12,0">
            <Grid.RenderTransform>
                <TranslateTransform x:Name="translateTransform" X="500" />
            </Grid.RenderTransform>
            <Grid.Resources>
                <Storyboard x:Key="hey" x:Name="StoryBoard1">
                    <DoubleAnimation Storyboard.TargetName="ContentPanel"
                     Storyboard.TargetProperty="Opacity"
                     From="0" To="1" Duration="0:0:10"
                     />
                    <DoubleAnimation Storyboard.TargetName="translateTransform"
                     Storyboard.TargetProperty="X"
                     From="500" To="0" Duration="0:0:10"/>
                </Storyboard>
            </Grid.Resources>
            <TextBlock x:Name="Txt2" Text="foo">
            </TextBlock>
        </Grid>