I have a refrence to a FrameworkElement
named _frameworkElement
I need to draw a FrameworkElement
on a drawingContext at the OnRender
event.
Like this:
protected override void OnRender(DrawingContext drawingContext)
{
drawingContext. ??
base.OnRender(drawingContext);
}
What I need is to consider any render transform applied to the _frameworkElement
Any clean solution for this problem ? Thanks
EDIT
Why would I need to override OnRender:
As I have a graphical application, user can draw shapes, and select multiple shapes using a selection tool that would draw rectangle selection area.
What I do is I re-parent selected shapes from stage Canvas to a selection Canvas which user can move and resize, after transformation on selection Canvas, user will click on stage Canvas, then I re-parent shapes to the stage Canvas.
The problem:
There is a bottleneck when removing children from Canvas to Canvas, Children.Remove & Children.Add will cost time to implement, specially when user selects large number of shapes to transform.
So ?
I thought not to re-parent selected shapes, instead draw them on the drawingContext of the selection Canvas by overriding OnRender
No I don't believe you can do that nor does it really make sense. The DrawingContext
is unique to each UIElement
and the framework handles calling the appropriate drawing methods as they're being enumerated (e.g. each element has it's own OnRender pass).
I'm not entirely following your design + problem, but maybe these will help?
WPF canvas performance- children.add called many times
How to draw line of ten thousands of points with WPF within 0.5 second?
If you need to deep-dive into how WPF renders, this is a good read.