ScaleTransform 更改在使用 Storyboard 后不起作用

ScaleTransform change Not work after Use Storyboard

我用 Storyboard 更改 ScaleTransform 并且工作正常,但更改后 ScaleTransform 不起作用,

示例: scaleTransform.ScaleX=1 使用故事板后: scaleTransform.ScaleX=2 当更改我的代码时 scaleTransform.ScaleX += 1; 但是 scaleTransform.ScaleX=2,

        private Storyboard _story = new Storyboard();

    private void CreateAnimation(double x, double y, TimeSpan delay)
    {
        var stScaleX = new DoubleAnimation(scaleTransform.ScaleX, x, delay);
        var stScaleY = new DoubleAnimation(scaleTransform.ScaleY, y, delay);
        stScaleX.SetValue(Storyboard.TargetProperty, mainCanvas);
        stScaleX.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("LayoutTransform.Children[0].ScaleX"));


        stScaleY.SetValue(Storyboard.TargetNameProperty, mainCanvas.Name);
        stScaleY.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("LayoutTransform.Children[0].ScaleY"));
        _story.Children.Add(stScaleY);
        _story.Children.Add(stScaleX);
        mainCanvas.Resources.Clear();

        _story.Changed += St_Changed;
        _story.Completed += St_Completed;
        _story.Begin(mainCanvas);
    }

    private void St_Completed(object sender, EventArgs e)
    {

        _story.Changed -= St_Changed;
        _story.Completed -= St_Completed;
        var newXy = new Point(_scalePoint.X, _scalePoint.Y);
        scrollViewer.ScrollToHorizontalOffset(newXy.X);
        scrollViewer.ScrollToVerticalOffset(newXy.Y);
        var zs = GetScaleTransform(mainCanvas);
        ZoomLevel = zs.ScaleX;
        _story.Stop();
        _story.Remove();
        mainCanvas.Resources.Clear();
    }

    private void St_Changed(object sender, EventArgs e)
    {
        var newXy = new Point(_scalePoint.X, _scalePoint.Y);
        scrollViewer.ScrollToHorizontalOffset(newXy.X);
        scrollViewer.ScrollToVerticalOffset(newXy.Y);
    }

     private void mainCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
    {
        var st = GetScaleTransform(mainCanvas);
        var zoom = e.Delta > 0 ? .6 : -.6;
        if (!(e.Delta > 0) && (st.ScaleX < .4 || st.ScaleY < .4))
            return;
        if (st.ScaleX <= 1 && zoom < 0) return;
        var relativeOnImage = e.GetPosition(mainCanvas);
        var relativeOnScreen = e.GetPosition(Grid1);

        scaleTransform.ScaleX = st.ScaleX+zoom;
        scaleTransform.ScaleY = st.ScaleY+ zoom;

        if (st.ScaleX < 1) st.ScaleX = 1;
        if (st.ScaleY < 1) st.ScaleY = 1;

        var newSizeX = Grid1.ActualWidth*st.ScaleX;
        newSizeX = ((newSizeX*relativeOnImage.X)/ Grid1.ActualWidth)- relativeOnScreen.X;
        var newSizeY = Grid1.ActualHeight * st.ScaleY;
        newSizeY = ((newSizeY*relativeOnImage.Y)/ Grid1.ActualHeight)- relativeOnScreen.Y;
        scrollViewer.ScrollToHorizontalOffset(newSizeX);
        scrollViewer.ScrollToVerticalOffset(newSizeY);
        IsZooming = st.ScaleX > 1 || st.ScaleY > 1;
    }

我爱过,

我更改了我的代码,并且成功了

    var oldDataX = scaleTransform.ScaleX;
        var oldDataY = scaleTransform.ScaleY;
        scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, null);
        scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, null);

        scaleTransform.ScaleX = oldDataX + zoom;
        scaleTransform.ScaleY = oldDataY + zoom;

了解更多信息:

https://msdn.microsoft.com/en-us/library/aa970493(v=vs.90).aspx http://www.codeproject.com/Tips/146505/WPF-Storyboard-animation-locks-properties-it-s-ani