I I am building a battleship game and I have a border in which I am placing a Grid in. I asked my instructor and he said "The border itself has the property of shrinking to the size of the object it contains. And you have no object in the border, so it has shrunk to zero". How do I solve this. This is the code of adding the border into the Grid.
public
void
BorderShot(Grid gridEnemy)
for
(
int
i =
0
; i <
10
; i++)
for
(
int
j =
0
; j <
10
; j++)
Border borderSecond =
new
Border()
BorderBrush = Brushes.Black,
BorderThickness =
new
Thickness(
5
),
Background = Brushes.Transparent
Grid.SetRow(borderSecond, i);
Grid.SetColumn(borderSecond, j);
gridEnemy.Children.Add(borderSecond);
borderSecond.MouseEnter += borderSecond_MouseEnter;
borderSecond.MouseLeave += borderSecond_MouseLeave;
borderSecond.MouseLeftButtonUp += BorderSecond_MouseLeftButtonUp;
borderSecond.MouseDown += borderSecond_MouseDown;
What I have tried:
I am pretty sure I wrote it correctly but to no avail
HorizontalAlignment
andVerticalAlignment
properties on the border, it will stretch to fill the available space.How have you defined your grid rows and columns? If you've set them to "auto" height/width, then they will shrink to the size of their content. Perhaps that's what your instructor meant?