Wpf – Style a border with a different brush color for each corner

bordercolorswpfxaml

I have created a static resource defining the border of a specific item in my xaml, but I can't find a good way to define a unique color for each side!

xaml:

<Border Style="{StaticResource SidePanelBorder}">
        <!-- rest of the xaml -->
</Border>

StaticResource:

<Style x:Key="SidePanelBorder">
    <Setter Property="Control.BorderBrush" Value="#FF363636" />
    <Setter Property="Control.BorderThickness" Value="1" />
</Style>

But I want to define one color for each side of the border, and eventually also a different Border thickness.

Any good techniques out there doing this?

Best Solution

Seems very hacky, but you could define borders within borders, and make only 1 side have a thickness. For example

<Border BorderThickness="0,0,0,10" BorderBrush="Green">
    <Border BorderThickness="0,0,10,0" BorderBrush="Blue">
        <Grid>
            <Button>Hello</Button>
        </Grid>
    </Border>
</Border>

would give a green border on the bottom and a blue border to the right. Isn't the prettiest piece of Xaml though.

Related Question