简体   繁体   中英

wpf how to clear a region of a DrawingVisual

So I have a DrawingVisual that is partially drawn, and then when I scroll I want to draw the new region and delete the old region from the DrawingVisual. How would I go about cropping out the old region?

Maybe you can simply override your current DrawingContext with empty rectangle - and then draw every new thang as you want, like:

var drawingVisual = ...;
var drawingContext = dv.RenderOpen();
var fullRect = new Rect(new Point(160, 100), new Size(320, 80)); //full size rect
drawingContext.DrawRectangle(new SolidColorBrush(), new Pen(), fullRect);
//other drawings...
drawingVisual.Close();

I think I found the answer to my question. The drawingvisual's instructions are stored inside it and you can just make a new one, then take the drawingcontext of the new one and draw the old visual while setting a crop region. Haven't tested it yet, but it should work. thanks for the tips everyone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM