WPF Rectangle with different stroke thickness on sides or Border with dashed stroke? WPF Rectangle with different stroke thickness on sides or Border with dashed stroke? wpf wpf

WPF Rectangle with different stroke thickness on sides or Border with dashed stroke?


Try this:

<Border BorderThickness="4,4,4,0"  Background="LightGreen">    <Border.BorderBrush>        <VisualBrush>            <VisualBrush.Visual>                <Rectangle                     Stroke="Green" Fill="LightGreen"                    StrokeDashArray="4 2"                    StrokeThickness="4"                    Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"                    Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}"/>            </VisualBrush.Visual>        </VisualBrush>    </Border.BorderBrush></Border>

It's border, so when put inside of grid it will use the available space and you can set different width for every side, it uses rectangle for visual brush, so you can easily set the borders to dashed.

enter image description here


A hacky solution but it works is to cover the side of the dashed Rectangle you want hidden:

            <Grid Width="100" Height="100">                <Rectangle Stroke="Green" StrokeThickness="4" StrokeDashArray="4 2"  Fill="LightGreen" Margin="10"/>                <Rectangle StrokeThickness="0" Height="4" Margin="10" VerticalAlignment="Bottom" Fill="LightGreen"/>            </Grid>

enter image description here