Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase StrokeThickness but maintain dimensions of Path

I have a Path that normally has a StrokeThickness of 1. Under certain circumstances, it needs to have a StrokeThickness of 10. When I increase the stroke thickness, I don't want the path to take any additional space.

By default, just increasing the StrokeThickness increases the rendered size of the path. So you get something like this (the blue outline extends beyond the black boundary):

Stroke expands beyond original boundary of path

This is what I'm trying to achieve (the blue outline stays within the black boundary):

Stroke is entirely inside original boundary of path

I can think of two mathematical ways to compensate for the increased StrokeWidth:

  1. Manually adjust the points of the triangle inward.
  2. Use a ScaleTransform on the Geometry of the Path.

Both of these would be somewhat problematic/complex. Is there an easier way?

like image 575
devuxer Avatar asked May 15 '12 04:05

devuxer


1 Answers

You could clip the path by its own geometry like this:

<Path ... Clip="{Binding Data, RelativeSource={RelativeSource Self}}"/>

but then you would need to double the StrokeThickness, since only half of the stroke is visible.

like image 75
Clemens Avatar answered Nov 16 '22 01:11

Clemens