szoszk
szoszk

Reputation: 449

PointerDownThemeAnimation application stops WP8

I'm confused why my app is closing, I have added the PointerDownThemeAnimation and it works fine but only one time, when I try to click it again the aplication stops. Why?
Here is my code:

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

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

and

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

Upvotes: 3

Views: 837

Answers (2)

Shawn Kendrot
Shawn Kendrot

Reputation: 12465

I have a blog post on how you can get tilt for "normal" items. What are you are trying to do can be achieved, but there is a problem in which the animation is still active. You need to stop the animation before playing it.

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

The post has a total of three ways to enable tilt plus a working sample to download

Upvotes: 0

Jerry Nixon
Jerry Nixon

Reputation: 31813

I think you found a genuine bug. Here's the workaround.

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>

Code-behind

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();
}

It's the this.MyRectangle.Projection = new PlaneProjection(); line you should notice. It's the only real change from your original code. Seems like the PointerUpThemeAnimation inadvertently destroys the PlaneProjection. This would have been okay if the PointerDownThemeAnimation would re-create it.

Best of luck!

Upvotes: 2

Related Questions