动画的动态自动调整大小控制

时间:2017-06-18 02:08:07

标签: c# wpf animation

我试图通过使用以下动画代码将元素从一个单元格移动到另一个单元格来为元素设置动画。

    private void PerformAnimation(List<Tuple<int, int>> _path, UIElement sprite)
    {
        Storyboard storyBoard = new Storyboard();

        Int32AnimationUsingKeyFrames row_intKeyFrame = new Int32AnimationUsingKeyFrames();
        row_intKeyFrame.Duration = new TimeSpan(0, 0, 0, 0, _path.Count * 500);

        Int32AnimationUsingKeyFrames col_intKeyFrame = new Int32AnimationUsingKeyFrames();
        col_intKeyFrame.Duration = new TimeSpan(0, 0, 0, 0, _path.Count * 500);

        for (int i = 1; i < _path.Count; i++)
        {
            row_intKeyFrame.KeyFrames.Add(new DiscreteInt32KeyFrame(_path[i].Item2));
            col_intKeyFrame.KeyFrames.Add(new DiscreteInt32KeyFrame(_path[i].Item1));
        }


        Storyboard.SetTargetProperty(row_intKeyFrame, new PropertyPath("(Grid.Row)"));
        Storyboard.SetTargetProperty(col_intKeyFrame, new PropertyPath("(Grid.Column)"));

        Storyboard.SetTarget(row_intKeyFrame, sprite);
        Storyboard.SetTarget(col_intKeyFrame, sprite);

        storyBoard.Children.Add(row_intKeyFrame);
        storyBoard.Children.Add(col_intKeyFrame);
        storyBoard.Begin();

    }

现在在一个单元格中,如果已经存在UIElement,我需要调整它们的大小并重新添加到该单元格。

enter image description here

   private void ResizeControls(int destRow, int destCol)
    {
            Grid Parent;
            List<UIElement> listOfElements = (BoardGrid.Children
                      .Cast<UIElement>()
                      .Where(i => Grid.GetRow(i) == destRow && Grid.GetColumn(i) == destCol)).ToList();

            if (listOfElements.Count > 1)
            {
               // Resize controls here
            }
   }

现在当一个元素从一个单元格移动到另一个单元格时,它可以处于2个状态,即调整大小或正常。每当它移动到已经具有UI元素的单元格时,我需要它们进入调整大小模式以便它们适合并且当它们移动到空闲单元格时(即没有任何UI控件的单元格,我需要将它们移回正常状态再次)。我该如何实现这一功能?每次有UIElement时,我是否需要在该单元格中添加任何面板?我正在寻找像自动调整大小动画

这样的东西

0 个答案:

没有答案