I'm using C# for Windows Phone 8.1.
What I have: I drag an transparent (not visible, but accessible) slider and a Grid follows the path of the slider with TranslateX
Manipulation:
<Grid Opacity="1" x:Name="innerGrid" HorizontalAlignment="Left" Margin="4,0,0,0">
<Grid.RenderTransform>
<CompositeTransform TranslateX="{Binding transXexact}" />
</Grid.RenderTransform>
[... stuff inside Grid ...]
</Grid>
<Slider x:Name="sliderPercent2" Minimum="0" Maximum="100" Value="0" Opacity="0" Style="{StaticResource customSliderBigOverlay}" ValueChanged="sliderPercent_ValueChanged" ManipulationMode="TranslateX" ManipulationStarted="sliderPercent2_ManipulationStarted" ManipulationCompleted="sliderPercent2_ManipulationCompleted" />
and the code side:
private void sliderPercent_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
if (sender != null)
{
myPercView.transX = Convert.ToInt32(e.NewValue);
myPercView.transXexact = e.NewValue * (Window.Current.Bounds.Width - 38 - 40 - 10) / 100;
}
}
private void sliderPercent2_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
Storyboard s = new Storyboard();
DoubleAnimation doubleAni = new DoubleAnimation();
doubleAni.To = 0;
doubleAni.Duration = new Duration(TimeSpan.FromMilliseconds(200));
Storyboard.SetTarget(doubleAni, innerGrid);
Storyboard.SetTargetProperty(doubleAni, "Opacity");
s.Children.Add(doubleAni);
s.Begin();
}
private void sliderPercent2_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
Storyboard s = new Storyboard();
DoubleAnimation doubleAni = new DoubleAnimation();
doubleAni.To = 1;
doubleAni.Duration = new Duration(TimeSpan.FromMilliseconds(300));
Storyboard.SetTarget(doubleAni, innerGrid);
Storyboard.SetTargetProperty(doubleAni, "Opacity");
s.Children.Add(doubleAni);
s.Begin();
}
now this works all fine, but I want to go further. Now I also want the innerGrid
to Zoom into 0. Thatfore I need ScaleX
and ScaleY
. I can add it to the Storyboard with this code:
var xAnim = new DoubleAnimation();
var yAnim = new DoubleAnimation();
xAnim.Duration = TimeSpan.FromMilliseconds(300);
yAnim.Duration = TimeSpan.FromMilliseconds(300);
xAnim.To = 1;
yAnim.To = 1;
Storyboard.SetTarget(xAnim, innerGrid);
Storyboard.SetTarget(yAnim, innerGrid);
Storyboard.SetTargetProperty(xAnim, "(UIElement.RenderTransform).(CompositeTransform.ScaleX)");
Storyboard.SetTargetProperty(yAnim, "(UIElement.RenderTransform).(CompositeTransform.ScaleY)");
BUT then it does NOT translate in X direction, when I move the slider, but just zoom into 0 on the position it was, when I started the manipulation.
What I want: Scale the Grid into 0 with animation while still applying TranslateX
Manipulation, so the Grid follows my movement while zooming out.
The trick was simpler as expected - One must just put another
Grid
over the fading outGrid
and animate those Grids seperately.