0

I am completely new to this forum, and still a beginner on WPF.

I am working on a project that requires the strokes on an inkcanvas to be animated. One of the animations required is "disappearing". I want to make the selected strokes gradually disappear with the click of a button, but appear at the end of the animation.

Since there is no opacity property for stroke, I tried using the ColorAnimation class along with storyboards. I have failed to make this code work, as I cannot target the strokes either using themselves or using their names, since they don't have any.

Right now I am thinking of implementing this system by gradually changing the color of the strokes to the color of the background, and at the end, resetting it back to its initial value. This is a costly loop, but I have no other ideas.

I would appreciate it if there are any other solutions you might share with me.

Thanks in advance.

Edit: I have not answered the comments, as I was dealing with other parts of the same project.

I have tried using the Alpha values that are stored in the DrawingAttributes, but I cannot change the value as it is not a variable. The same goes with RGB values. I have no idea on how to make the strokes disappear in a loop. I have already implemented most of the project, so I just need something to slowly make them disappear. Below you can find an example where I change the stroke itself to animate it.

 private int dropOffset = 1;
    private void DropAnimation()
    {
        m = new Matrix();
        m.Translate(0, dropOffset);

        animStrokes.Transform(m, false);
        YChange += dropOffset;
        dropOffset += 2;
    }

And in another class, I have

public void AnimateStrokes(Dispatcher canvasDispatch)
    {
        Stopwatch initial = Stopwatch.StartNew();
        while (initial.ElapsedMilliseconds < 2000)
        {
            foreach (Animation ai in AnimationList)
            {
                ai.animateSelected();
            }
            canvasDispatch.Invoke(new Action(() => { }), DispatcherPriority.Render);
            Thread.Sleep(50);
        }
        foreach (Animation a in AnimationList)
        {
            a.undoAnimation();
        }
        canvasDispatch.Invoke(new Action(() => { }), DispatcherPriority.Render);
    }

I know that it's not healthy to pass dispatcher like this, but it suffices for now.

Thanks again in advance.

  • You can edit the Stroke colour's alpha value, but you'll still have to loop through them. You say it's a costly loop, but have you benchmarked it or are you assuming it's too slow? – keyboardP Dec 29 '11 at 15:15

1 Answers1

0
InkCanvas1.DefaultDrawingAttributes.Color = Color.FromArgb(100, 0, 255, 255);

Might be a bit late but help for others none the less! The 100 is the alpha value which basically acts like an opacity value!! Mess with that and you will be able to change how transparent your strokes are :)