如何在Xamarin.Forms中的网格中启用边框
问题描述:
我正在Xamarin.Forms中构建一个网格. 我想添加表格等边框. 我以为可以在定义行和列时添加边框,但是失败了. 谁能帮我? 这是我当前的代码.
I'm building a grid in Xamarin.Forms. And I'd like to add borders like tables. I thought that I could add the border when defining rows and columns, but failed. Can anyone help me? This is my current code.
Grid grid = new Grid {
VerticalOptions = LayoutOptions.FillAndExpand,
RowDefinitions = {
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
},
ColumnDefinitions = {
new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength (5, GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) },
}
};
答
GridView
没有Border
属性,但是:
只需将grid.BackgroundColor
设置为所需的边框颜色值,然后将grid.ColumnSpacing
和grid.RowSpacing
设置为某个值,并确保添加到网格的所有控件都正确设置了自己的BackgroundColor
.
Just set grid.BackgroundColor
to your desired border color value, then set grid.ColumnSpacing
and grid.RowSpacing
to some value and make sure all controls you add to the grid have own BackgroundColor
set correctly.