3

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>
Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
szoszk
  • 349
  • 7
  • 22
  • I think you have wrongly tagged your question - probably you are using WP8.1 Runtime (Windows Store Apps). Correct me if I'm wrong. – Romasz Jun 04 '14 at 05:23
  • @Romasz I think thats right – szoszk Jun 04 '14 at 17:00
  • As I've tried your code, you are getting an exception conected with PlaneProjection. Have you tried to follow [guidelines at MSDN](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj649432.aspx) and [some information here](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.media.animation.pointerdownthemeanimation.aspx)? – Romasz Jun 04 '14 at 17:11
  • Did you find a solution? Both answers didn't work for me... Still throwing NullReferenceException... – Rico Suter Dec 18 '14 at 07:22
  • It seems that this is bug in XAML for Windows Phone: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/adf98a1f-13d4-4600-a4b4-ee1555d9bace/pointerdownthemeanimation-crashing?forum=wpdevelop – Rico Suter Dec 18 '14 at 07:31

2 Answers2

2

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!

Jerry Nixon
  • 31,313
  • 14
  • 117
  • 233
0

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

Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41