2

I'm developing an app using Windows Phone 8.1 RT framework. There are some grid controls I would like to add tilt effect to. How do I do it?

Harsha Bhat
  • 718
  • 10
  • 25

1 Answers1

5

In Windows Runtime there are some nice animations you can use for that purpose - reference at MSDN. There are few ways you can reach your goal:

  1. The easiest one would be to put your Grid inside the Button control which has Tilt effect as default. You can also easily use custom style of your button - reference at this answer.

  2. You may design your own Control and use VisualStateManager.GoToState to switch between the states. Here at MSDN is nice short example how to do this.

  3. You can define Storyboard using theme animations and Begin() upon pointer pressed/released. A short example:

    In XAML:

    <Grid Name="animatedGrid" PointerPressed="animatedGrid_PointerPressed" PointerReleased="animatedGrid_PointerReleased">
      <Grid.Resources>
        <Storyboard x:Name="animateUp">
            <PointerUpThemeAnimation TargetName="animatedGrid" />
        </Storyboard>
        <Storyboard x:Name="animateDown">
            <PointerDownThemeAnimation TargetName="animatedGrid" />
        </Storyboard>
      </Grid.Resources>
      <Rectangle Fill="Tomato" Width="200" Height="200"/>
    </Grid>
    

    In code behind:

    private void animatedGrid_PointerPressed(object sender, PointerRoutedEventArgs e)
    {
        animatedGrid.Projection = new PlaneProjection();
        animateDown.Begin();            
    }
    
    private void animatedGrid_PointerReleased(object sender, PointerRoutedEventArgs e)
    {
        animateUp.Begin();
    }
    

The example above covers a little strange behaviour pointed out in this question and found workaround by Jerry Nixon - MSFT.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154
  • This doesn't seem to work for me... Does it only work for grids? – Atley Jul 18 '14 at 01:41
  • @Atley How do I suppose to know what's wrong with your code? Maybe insted of asking in comments (have you also downvoted it?) you can think of asking your own question with specific problem? BTW - answer includes *Grid*, because it's quite nice and universal, as you can put many things inside. – Romasz Jul 18 '14 at 05:13
  • Hi, is it possible define also Storyboards in code behind? – Jakub Krampl Oct 30 '14 at 22:07
  • @kubakista Yes, it is possible. – abdhoms Dec 22 '14 at 13:17