3

我很困惑为什么我的应用程序正在关闭,我添加了 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>
4

2 回答 2

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不经意间毁了PlaneProjectionPointerDownThemeAnimation如果重新创建它,这将是可以的。

祝你好运!

于 2014-06-05T16:13:46.723 回答
0

我有一篇关于如何获得“正常”项目倾斜的博客文章。可以实现您正在尝试做的事情,但是存在动画仍然处于活动状态的问题。您需要在播放动画之前停止动画。

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

该帖子共有三种启用倾斜的方法以及下载的工作示例

于 2014-08-13T21:20:04.037 回答