Xamarin Forms Controls with borders

杀马特。学长 韩版系。学妹 提交于 2020-01-14 13:26:09

问题


In my Xamarin forms application I want to add borders to a Grid / StackPanel. Also the background color will be transparent. I used frame control , but when I set background color to transparent the border also not shown. Please help me?


回答1:


You basically have two possibilies, since this is not yet supported in Forms, where the first is to use BoxViews as explained on SO in this post.

Otherwise, you can wrap a StackLayout around your View (the StackLayout or Grid as you mentioned) with a BackgroundColor and Padding of 0.5 as explained here.

Let me know if you need more concrete examples.




回答2:


There's no Border property for GridView, but:

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.




回答3:


A BoxView can be used for border purpose. In the following XAML code, note that FillAndExpand option is used for HorizontalOptions of the StackLayout

<StackLayout VerticalOptions="Start" HorizontalOptions="FillAndExpand"  >
    <BoxView  BackgroundColor="Cyan" HeightRequest="5" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
    <BoxView  BackgroundColor="Cyan" HeightRequest="1" VerticalOptions="Start" HorizontalOptions="FillAndExpand" />                     
</StackLayout>



回答4:


There's no Border property for GridView, but:

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.

You also have to set Grid.Padding to whatever the border width you want.



来源:https://stackoverflow.com/questions/32629200/xamarin-forms-controls-with-borders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!