PointerDownThemeAnimation应用程序停止WP8

时间:2014-06-03 19:32:48

标签: c# windows-runtime winrt-xaml windows-phone-8.1 win-universal-app

我很困惑为什么我的应用程序正在关闭,我添加了PointerDownThemeAnimation并且它工作正常但只有一次,当我再次单击它时,应用程序停止。为什么呢?
这是我的代码:

private void staryrynek1(object sender, PointerRoutedEventArgs e)
{
    pointerDownStoryboard.Begin();
}

private void staryrynek(object sender, PointerRoutedEventArgs e)
{
    pointerUpStoryboard.Begin();
    this.Frame.Navigate(typeof(StaryRynek));
}

<Grid x:Name="staryrynek_grid" Margin="10,92,10,0" VerticalAlignment="Top" PointerPressed="staryrynek1" PointerReleased="staryrynek">
        <Grid.Resources>
            <Storyboard x:Name="pointerDownStoryboard">
                <PointerDownThemeAnimation TargetName="staryrynek_grid" />
            </Storyboard>
            <Storyboard x:Name="pointerUpStoryboard">
                <PointerUpThemeAnimation TargetName="staryrynek_grid" />
            </Storyboard>
        </Grid.Resources>
        <Grid.Background>
            <SolidColorBrush Color="Black" Opacity="0.495"/>
        </Grid.Background>
        <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Width="380" FontSize="29.333" Text="Stary Rynek"/>
    </Grid>

2 个答案:

答案 0 :(得分:2)

我认为你发现了一个真正的错误。这是解决方法。

XAML

<Grid>
    <Grid.Resources>
        <Storyboard x:Name="PointerDownStory">
            <PointerDownThemeAnimation TargetName="MyRectangle" />
        </Storyboard>
        <Storyboard x:Name="PointerUpStory">
            <PointerUpThemeAnimation TargetName="MyRectangle" />
        </Storyboard>
        <Style TargetType="Rectangle">
            <Setter Property="Width" Value="300" />
            <Setter Property="Height" Value="200" />
            <Setter Property="Fill" Value="White" />
        </Style>
    </Grid.Resources>
    <Rectangle x:Name="MyRectangle"
               PointerPressed="Grid_PointerPressed"
               PointerReleased="Grid_PointerReleased" />
</Grid>

代码隐藏

private void Grid_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    this.MyRectangle.Projection = new PlaneProjection();
    PointerDownStory.Begin();
}

private void Grid_PointerReleased(object sender, PointerRoutedEventArgs e)
{
    PointerUpStory.Begin();
}

您应注意this.MyRectangle.Projection = new PlaneProjection();行。它是您原始代码中唯一真正的变化。好像PointerUpThemeAnimation无意中破坏了PlaneProjection。如果PointerDownThemeAnimation重新创建它,那就没关系。

祝你好运!

答案 1 :(得分:0)

我有一个blog post关于如何倾斜&#34;正常&#34;项目。您可以实现的目标是什么,但是存在动画仍处于活动状态的问题。你需要在播放之前停止动画。

private void staryrynek1(object sender, PointerRoutedEventArgs e)
{
    pointerDownStoryboard.Stop();
    pointerDownStoryboard.Begin();
}

该帖子共有三种启用倾斜功能和下载工作样本的方法