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

Categories

0 votes
727 views
in Technique[技术] by (71.8m points)

wpf - 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?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...