如何在Xamarin.Forms中的网格中启用边框 [英] How to enable borders in Grid in Xamarin.Forms

查看:496
本文介绍了如何在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.ColumnSpacinggrid.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.

这篇关于如何在Xamarin.Forms中的网格中启用边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆