Is it possible to hide only Strokes in WPF InkCanvas?

HoneyBee 186 Reputation points
2022-02-16T08:37:47.437+00:00

In my program I tested Undo and Redo and finally implemented it.

And while this test code was reflected in this project, one issue occurred.

It has a function to draw on the InkCanvas and make it invisible or visible again.

The reason this function is needed is that the InkCanvas has an image in the Background.

To hide the picture, copy and store the current stroke through Clone() in the StrokeCollection.
And clear all strokes on the canvas (InkCanvas.Strokes.Clear();)

When making it visible again, clone() the temporary StrokeCollection to restore the stroke to the current InkCanvas.

But here a problem arises.

Obviously, in order to implement Undo and Redo, in the order of the strokes stored in a separate stack.
If you delete or add to the restored stroke, it will not work.

Add and Remove do not work.
(Strokes for Undo and Redo that are kept in the Stack exist.)

If you remove
It is not erased.

Why?

Is there a way to handle only the Visible of the Stroke without doing the Stroke Clear?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,760 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.