Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
701 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...