Home > Software design >  WPF Path object StrokeThickness setting has no effect
WPF Path object StrokeThickness setting has no effect

Time:11-23

I'm drawing a simple Path shows a simple triangle pointing down. This is what it's supposed to draw (shown on top of other stuff)

enter image description here

It works great except for one thing: No matter what value I give to the StrokeThickness, the triangle what shows up on my screen is the above picture. It never gets any thicker or thinner.

Here is the XAML. In this I have set the StrokeThickness to the absurd value of "200" just to see if anything would change. It didn't

<Path  Grid.Row="0" 
    HorizontalAlignment="Right" VerticalAlignment="Top"
    Width="30" Height="30" Stretch="Uniform" 
    StrokeThickness="200"
    Data="{StaticResource ReplicaSurfacePathGeometry}"
    Fill="White" 
    />

This is the Geometry resource being drawn

<PathGeometry x:Key="ReplicaSurfacePathGeometry" FillRule="NonZero">
    <PathGeometry.Figures>
        m 600 1034.3 -501.52 -868.68
        h1003
        z
        
        m 0 -120 397.6 -688.69
        h-795.2
        z
    </PathGeometry.Figures>
</PathGeometry>

When I debug and use the live visual tree and look at the actual live properties of the path, it shows the StrokeThickness is indeed "200". But the line stays skinny.

I know this is something dumb on my part. What am I missing here?

CodePudding user response:

The white line is the difference of the areas of the two triangle segments in the PathGeometry. It has nothing to do with a potential Stroke of the Path.

In order to make the StrokeThickness effective, set the Stroke property in conjunction with a more simple Geometry:

<Path Data="M0,0 L2,0 1,1.73 Z"
      Width="30" Height="30" Stretch="Uniform" 
      Stroke="White" StrokeThickness="2"/>
  • Related