Stroke Thickness

I am currently evaluting Zoompanel for my application.

I meet the following problem:
When zooming in a shape ,the stroke thickness is also zoomed in, and I dont' want at all this behavior.
(Example: A rectangle with a thin border . I don't want the border to become "fat" when zooming)

Is there a way to keep the stroke thickness constant when zooming ?

I suspect I have to work a little. My first idea is to apply a ScaleTransform to my shape elements with an "inverse" zoom factor.
But which zoom Factor should I apply ?
Thanks for help, or any other idea!

Unfortunately WPF does not support scale invariant thickness. This is supported in GDI+ and is very useful for vector drawing applications. In WPF the line thickness is always scaled.

There is already a WPF feature request to add this also to WPF - please vote for it on

However it is probably also possible to implement this in the current version of WPF with manually updating the StrokeThickness on all shapes.

With ZoomPanel this can be done this way:

The current zoom factor can be get from the current Viewbox property from ZoomPanel.

When Width and Height of Viewbox is 1, than we are showing 100% of the image (Viewbox = (0 0 1 1). Viewbox is (0 0 0.5 0.5) than we are showing just the upper 1/4 of the image - here the x scale is factor 2 and y scale is 2 - the overall scale is 4.

So the zoom factor can be calculated with 1 / (Viewbox.Width * Viewbox.Height).

You can subscribe to ViewboxChanged event on ZoomPanel to be informed about any Viewbox changes.

Now you will have to adjust all the stroke thicknesses regarding the zoom factor.

I did not try this yet.
I and probably some others would be very interested in knowing how this worked, so please post a feedback.
Andrej Benedik
Sorry for late answer.

I got good results; but by multiplying StrokeThickness of my elements by ViewBox.Width only ( viewBox width = Viewbox.height in my applicaiton)

Multiply by (Viewbox.Width * Viewbox.Height) make the line so thin when zooming , that it disappear.

Your explanations sounds clear and I don't understand your formula does not work for me.

So what I do precisely is :
1. listening to ViewBOwChanged
2. In handling method
2.1 I calculate Zoom value . Zoom = viewBox width
2.2 I Set StrokeThickness for al my shape in the canvas:
StrokeThickness = 3* ViewBox width ( 3 is my default value, when Zoom =1)

Now I face another problem: I have 1000 thousands shape on my canvas,and setting StrokeThickness is costly ! It really makes the zoom much slower.
Are there any news from WPF Team, do they plan to make this useful development ?

Forum Jump:

Users browsing this thread:
1 Guest(s)