【问题标题】:animating a custom grid via code behind in wp8.1通过 wp8.1 中的代码为自定义网格设置动画
【发布时间】:2015-05-20 15:15:49
【问题描述】:

我正在尝试使用网格创建动画。这是一个登录屏幕。每当用户点击忘记密码时,我希望第二个网格从顶部开始动画并滑动直到它停在中心并且点击它的可见性会发生变化。我知道如何使用混合来做到这一点,但问题是我有一种从代码背后做这件事的冲动。为此,我正在使用 doublekeyframe 类。在知道为第二个网格设置动画的代码中存在问题时遇到了真正的麻烦。不知道是什么问题以及如何制作动画需要如此严肃的帮助。

这是我的代码:

    Grid gd= this.FindName("SecondaryGrid") as Grid;
    DoubleAnimationUsingKeyFrames dm=new DoubleAnimationUsingKeyFrames();
    LinearDoubleKeyFrame l1=new LinearDoubleKeyFrame();
    LinearDoubleKeyFrame l2=new LinearDoubleKeyFrame();



    l1.Value=-703.203;
    l1.KeyTime=TimeSpan.FromSeconds(0);

    l2.Value=0;
    l2.KeyTime=TimeSpan.FromSeconds(1);

    dm.KeyFrames.Add(l1);
    dm.KeyFrames.Add(l2);

    dm.Duration=new Duration(TimeSpan.FromMilliseconds(3000));  

    Storyboard sb = new Storyboard();
    sb.Children.Add(dm);



      Storyboard.SetTarget(dm, gd);
      Storyboard.SetTargetName(dm, gd.Name);
      Storyboard.SetTargetProperty(dm, "Position");

      sb.Begin();
      SecondaryGrid.Visibility = Visibility.Visible;

【问题讨论】:

  • 是否应该在动画开始之前将辅助网格可见性设置为可见?
  • 没关系....我也试过这种方式:(

标签: c# animation windows-phone-8


【解决方案1】:
Grid gd = this.FindName("SecondaryGrid") as Grid;
        DoubleAnimationUsingKeyFrames dm = new DoubleAnimationUsingKeyFrames();
        LinearDoubleKeyFrame l1 = new LinearDoubleKeyFrame();
        LinearDoubleKeyFrame l2 = new LinearDoubleKeyFrame();



        l1.Value = -703.203;
        l1.KeyTime = TimeSpan.FromSeconds(0);

        l2.Value = 0;
        l2.KeyTime = TimeSpan.FromSeconds(1);

        dm.KeyFrames.Add(l1);
        dm.KeyFrames.Add(l2);

        dm.Duration = new Duration(TimeSpan.FromMilliseconds(30000));

        Storyboard sb = new Storyboard();
        sb.Children.Add(dm);



        Storyboard.SetTarget(dm, gd);
        Storyboard.SetTargetName(dm, gd.Name);
        Storyboard.SetTargetProperty(dm, "(UIElement.RenderTransform).(CompositeTransform.TranslateY)");

        sb.Begin();

享受:)

编辑

我所做的是转到 XAML 并现在在其属性中创建了一个 SecondaryGrid 去渲染转换并单击编辑并将 Y 值设置为 1 然后我在 XAML 中看到我们得到了

    <Grid.RenderTransform>
         <CompositeTransform TranslateX="0" TranslateY="1"/>
  </Grid.RenderTransform>

因此我知道,由于没有位置属性,所以我需要将 targetProperty 设置为渲染变换,并且我应该更改 Y 属性,因为它需要从上到下出现在 Composite Transform.TranslateY 中

【讨论】:

  • 谢谢兄弟.....这很有帮助......我很长一段时间以来一直坚持下去。你能解释一下吗?你写的那一行是什么意思。我们是否需要使用类似的东西来从 x 轴转换?谢谢
  • 详情请查看编辑。干杯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多