'WPF Drawing line on top of polygons gives bad lag
I am currently on a WPF project, where I load a bitmap and have a Canvas on top of it and then I draw a bit of stuff on it by adding to the canvas (only adding once). Disclaimer: I know WPF is slow with this kinda stuff but it seems to have good enough performance until this point. I am drawing the bitmap and on the Canvas I add a few icons, then by clicking I can add 2 points and when you created both points they will be connected by a Line. Before that, a lot of polygons are drawn (basically Rectangles but as polygons), maybe a few hundred.
When I draw the polygons, it runs very smooth, when I add the line it runs very smooth, but when I have both on the screen suddenly it lags immensely and it doesn't matter how many rectangles there are. The Ellipses that the line is connecting have no performance impact though, it only starts when BOTH the Line and the Polygons are drawn at the same time
Maybe someone has an insight that I don't have and can help
Have a nice day, :) Matty
Edit: I enabled Bitmap Caching for the canvas which makes the performance of the Rectangles better in general, but drawing the Line still just makes it lag.
Edit 2: After the second PC restart I suddently don't have that lag problem anymore lol
Solution 1:[1]
Someone didn't like the question anyways :D
I now added Bitmap Caching with a Render Size of 8, which makes the Rectangles more performant.
After a lot of digging and debugging I had some code that was running way too often which now only runs when it needs to, that fixed the lag
Cheers
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matty |

