WPF PathGeometry / RotateTransform optimization
I am having performance issues when rendering / rotating WPF triangles
If I had a WPF triangle displayed and rotated somewhat around the center point, I can do it in one of two ways:
-
Programmatically define the points and their offsets in the backend, use XAML to just place them on the canvas where they belong, it would look like this:
<Path Stroke="Black"> <Path.Data> <PathGeometry> <PathFigure StartPoint ="{Binding CalculatedPointA, Mode=OneWay}"> <LineSegment Point="{Binding CalculatedPointB, Mode=OneWay}" /> <LineSegment Point="{Binding CalculatedPointC, Mode=OneWay}" /> <LineSegment Point="{Binding CalculatedPointA, Mode=OneWay}" /> </PathFigure> </PathGeometry> </Path.Data> </Path>
-
Create the "same" triangle every time and then use RenderTransform (Rotate) to place it where it belongs. In this case, the rotation calculations get confusing because I don't have access to how they are done.
<Path Stroke="Black"> <Path.Data> <PathGeometry> <PathFigure StartPoint ="{Binding TriPointA, Mode=OneWay}"> <LineSegment Point="{Binding TriPointB, Mode=OneWay}" /> <LineSegment Point="{Binding TriPointC, Mode=OneWay}" /> <LineSegment Point="{Binding TriPointA, Mode=OneWay}" /> </PathFigure> </PathGeometry> </Path.Data> <Path.RenderTransform> <RotateTransform CenterX="{Binding Centre.X, Mode=OneWay}" CenterY="{Binding Centre.Y, Mode=OneWay}" Angle="{Binding Orientation, Mode=OneWay}" /> </Path.RenderTransform> </Path>
My question is which one is faster?
I know I should test it myself, but how to measure the render time of objects with such detail. I would need to know how long the actual render time is for the form, but since I'm not the one who starts redrawing, I don't know how to record the start time.
source to share
Have you tried using Perforator or Visual Profiler included with WPF Productivity Tools ? It appears from the documentation that these tools should be able to provide you with the information you are looking for. You will need to create the application in the first way, test it with these tools, take note of the performance information, and then do it again, and the application builds the second way of comparison.
source to share