I'm building a picture viewer with two visual states.
A) Application base state (no visualstate active)
1) "base" state (visualstate, empty storyboard)
2) "grid" with all the images (visualstate that scales images to quarter size)
I want to change between the visual states with gestures. Pinching an image currently does this. I also want the pinch gesture to scale the image when I pinch (OnPinchDelta). This is only working in A) no visual state active. Once I launch a visual state 1) or 2) pinching no longer works. It still launches the visualstate change but doesn't scale the image while pinching.
How can I modify the image scale when I have a visual state active or how can I exit any active visual state to not have any visualstate/storyboard running (I think the latter is impossible)?
The reason why the pinching no longer scales the image while pinching is because it somehow conflicts with the visualstate. On app launch everything works but once a visual state has been activated it no longer works. If in app launch I set the visualstate to 1) it doesn't work even once.
EDIT: I built a simplified example. Here's the relevant XAML (copy paste of the rest didn't work but otherwise it's just the default WP page template with toolkit reference):
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Grid">
<Storyboard>
<DoubleAnimation Duration="0" To="0.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="image" d:IsOptimized="True"/>
<DoubleAnimation Duration="0" To="0.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="image" d:IsOptimized="True"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"/>
<Image x:Name="image" Source="cheetah-picture.jpg" Stretch="Uniform" VerticalAlignment="Top">
<Image.RenderTransform>
<CompositeTransform x:Name="ImageTransformation"/>
</Image.RenderTransform>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchDelta="OnPinchDelta" PinchCompleted="OnPinchCompleted" />
</toolkit:GestureService.GestureListener>
</Image>
</Grid>
Here's the .CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace Pincher
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void OnPinchDelta(object sender, PinchGestureEventArgs e)
{
ImageTransformation.ScaleX = 1 * e.DistanceRatio;
ImageTransformation.ScaleY = ImageTransformation.ScaleX;
}
private void OnPinchCompleted(object sender, PinchGestureEventArgs e)
{
bool squeezing = (e.DistanceRatio < 1) ? true : false;
if (squeezing == true)
{
VisualStateManager.GoToState(this, "Grid", true);
MessageBox.Show("grid");
}
else
{
VisualStateManager.GoToState(this, "Normal", true);
MessageBox.Show("normal");
}
}
}
}
To wrap up. Changing visual states works with pinching. Actually scaling the picture while pinching only works when no visual state is active. How can you scale items while a visual state is active?