I need to create a generic triangle in WPF indicating coordinates, stroke and colors for stroke and filling area. The problem is that i want indicate as color also the Transparent for stroke, meaning than using the same coordinate, I want to draw, all inside this shape, a transparent stroke that replace for his thickness the fill color, but it seems not be possible (I found and solved with a triky the same problem for Circle and Rectangle shapes, but with Polygon it doesn't work: Drawing a WPF shape, as a Rectangle: StrokeThickness halve if Stroke is Transparent ). The code I use now include a clip because the stroke grow part inside and part outside the coordinate profile, I need to remove outside part, and some converter to give array of points in the correct way:
<UserControl.Clip>
<PathGeometry>
<PathFigure StartPoint="{Binding Triangle.Points, Converter={StaticResource PointLocationClipConverter}}" IsClosed="True">
<PolyLineSegment Points="{Binding Triangle.Points, Converter={StaticResource PointCollectionClipConverter}}" />
</PathFigure>
</PathGeometry>
</UserControl.Clip>
<Grid x:Name="_grid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Polygon Points="{Binding Triangle.Points, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource PointCollectionConverter}}" Grid.Row="0" Grid.Column="0" Margin="0,0,0,0"
Width="{Binding ActualWidth, ElementName=_grid}"
Height="{Binding ActualHeight, ElementName=_grid}"
Stroke="{Binding Triangle.BorderColorBrush}"
StrokeThickness="{Binding Triangle.Thick, Converter={StaticResource PoligonThickConverter}}"
Fill="{Binding Triangle.BackgroundBrush}" />
</Grid>
What I have at this moment is:
what I want instead is:
notice: for both example posted, the first image has solid color for Stroke and Fill area, second image has Transparent on Stroke and solid color for Fill area (and here is the problem), third image has solid color for Stroke and Transparent for Fill area. All images have same coordinates and StrokeThickness value.
Thanks for help!
Geometry.GetWidenedPathGeometry
for the stroke part andGeometry.Combine
for the interior. – Clemens