Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Border Corner Radius Fill Atrocity

Tags:

wpf

I have a border defined like so:

<Border x:Name="BaseBar" BorderThickness="1,1,1,2" Height="29" CornerRadius="0,0,16,16" Grid.Row="2">
<Border.BorderBrush>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF6E6E6E" Offset="0.004"/>
        <GradientStop Color="#FF1A1A1A" Offset="0.043"/>
    </LinearGradientBrush>
</Border.BorderBrush>
<Border.Background>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF313131" Offset="0"/>
        <GradientStop Color="#FF232323" Offset="1"/>
    </LinearGradientBrush>
</Border.Background>

It doesn't fill correctly when the corners have a radius, though. Here is an image of the bottom left corner:

Border fills poorly at radius corner

You can clearly see the brighter background shining through the darker foreground. Is there a way to alleviate this?

EDIT: Additional picture, showing that it is the background shining through:

Border fills poorly at radius corner

In this case, only the white half of the background is seen, whereas the black half (while also getting through) is not really detectable.

like image 941
jomido Avatar asked Jan 10 '12 16:01

jomido


People also ask

What is the use of border radius?

Definition and Usage. The border-radius property defines the radius of the element's corners. Tip: This property allows you to add rounded corners to elements! This property can have from one to four values. Here are the rules:

Does border radius apply to all 4 corners of an element?

With just one value, border-radius will the same on all four corners of an element. But that need not be the case. You can specifiy each corner separatedly if you wish: You can also specify two or three values. MDN explains it well: If one value is set, this radius applies to all 4 corners.

How to create inverted corner border radius using CSS?

Create Inverted Corner Border Radius 1 Using four circles and using the css property position to position the circles. 2 Using the pseudo class :before and :after and the position property. More ...

What are the different border-radius values for each corner?

Here are the rules: Four values - border-radius: 15px 50px 30px 5px; (first value applies to top-left corner, second value applies to top-right corner, third value applies to bottom-right corner, and fourth value applies to bottom-left corner): Three values - border-radius: 15px 50px 30px;


1 Answers

In this case, I usually nest two Borders inside each other. This only works if the inner fill color will be opaque, but yours already is so this should be fine.

So instead of, for example (using solid colors instead of gradients to make the example easier to follow):

<Border BorderThickness="1,1,1,2" CornerRadius="0,0,16,16"
        BorderBrush="Blue" Background="Gray">
  ...
</Border>

you could instead use:

<Border CornerRadius="0,0,16,16" Background="Blue">
  <Border CornerRadius="0,0,15,15" Background="Gray" Margin="1,1,1,2">
    ...
  </Border>
</Border>

So the outer Border uses the "border" color as its Background, and then the inner Border sets its Margin to the "border width" and then uses the real "background" color for its Background. The effect is the same, but the semi-transparent seam is gone.

To make it look right, you need to tweak the inner border's CornerRadius -- it's inside the border, so it's a slightly smaller radius than the outside corner. If the border was 1 pixel wide, then you'd want your CornerRadius to be 1 pixel smaller; but since you've got an uneven border, you'll probably just want to eyeball it to see what looks right.

like image 167
Joe White Avatar answered Sep 27 '22 18:09

Joe White