user811804
user811804

Reputation: 43

How do I create a dashed border with rounded top corners in WPF?

I can create a Border element and only make the top corners rounded or I can create a Rectangle element (acting as a border) with a dashed stroke.

Now how do I create a border that actually can do BOTH these things?

(I do not want rounded bottom corners!)

Upvotes: 3

Views: 504

Answers (1)

Fredrik Hedblad
Fredrik Hedblad

Reputation: 84676

I created a UserControl which contains a Border whose Background is a VisualBrush made up of four Rectangles, each occupying the same space but has the Clip property set to one of the four corners. Combining these Rectangles and you get a pretty similar effect to what you're after. It also has the relevant Dependency Properties from Border and Rectangle combined

Use it like this

<Controls:RectangleBorder Stroke="Red"
                          StrokeThickess="6"
                          StrokeDashArray="1.0 1.0"
                          CornerRadius="20,20,0,0">
    <Button Content="Test" Margin="5"/>
</Controls:RectangleBorder>

And the result looks like this

enter image description here

Uploaded the RoundedRectangleLibrary here if you want to try it out
http://www.mediafire.com/?44300c4xmy3d1m6

Upvotes: 2

Related Questions