翻译操作时WP8.1故事板缩放

时间:2015-06-10 07:09:45

标签: xaml animation storyboard windows-phone-8.1

我在Windows Phone 8.1中使用C#。

我拥有的内容:我拖动一个透明(不可见但可访问)的滑块,一个网格跟随滑块的路径TranslateX操纵:

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

和代码方:

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

现在这一切都很好,但我想更进一步。现在我还希望innerGrid放大到0.我需要ScaleXScaleY。我可以使用以下代码将其添加到Storyboard:

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)");

但是当我移动滑块时,它不会在X方向上平移,而是在我开始操作时只是放大到它的位置。

我想要的:使用动画将网格缩放为0,同时仍然应用TranslateX操作,因此网格在缩小时跟随我的移动。

1 个答案:

答案 0 :(得分:0)

诀窍比预期的更简单 - 一个人必须在淡出Grid上放另一个Grid并单独为这些网格制作动画。