0

I'm trying to make a WPF application and was trying to make a square border. I want it to be 10 pixels away from the top, bottom and right edges of the grid. I tried messing with the XAML code but that just produced all sorts of malformations, so I used Visual Studio's Properties tab instead. If I set the right and bottom border to 0 it looks fine, but it covers the edge like this. Code:

<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Right" Height="180" Margin="604,10,0,0" VerticalAlignment="Bottom" Width="180"/>

If I however add a 10 border to right and bottom (which is what I've used in my previous WPF apps so far) this happens. Code:

<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Right" Height="180" Margin="604,10,10,10" VerticalAlignment="Bottom" Width="180"/>

They both looks the same in the preview btw. Also sorry, I can't post direct images yet, since I don't have enough reputation.

Thrith
  • 35
  • 8
  • Use Margin="0,10,10,10" – HYA May 11 '20 at 21:22
  • You need to count what the parent control size is. If it is smaller than your border size, of course your border will be clipped. Can you show us how you write the Border's parent control? Or how do you define the Grid.RowHeight? Hint: it should be at least 180 + 10 + 10 in height. – kurakura88 May 12 '20 at 01:49

1 Answers1

1

The reason why the left border is not visible is because of the 604 as the left margin set that to 0 and you should be all good.

<Border BorderBrush="Black" BorderThickness="1" Height="180" Width="180" Margin="0,10,10,10" HorizontalAlignment="Right" VerticalAlignment="Bottom"/>

That being said, I do not recommend using fixed Height and Width in your XAML UI.

I've already got a few answers on this so feel free to check them out:

iam.Carrot
  • 4,976
  • 2
  • 24
  • 71