xaml - How to set BoxView or Frame height equal to Screen Height in Xamarin Forms?
问题描述
I am having a BoxView
I need to set its Height and width equal to screen size. I am using StackLayout
and setting HeightRequest="500" WidthRequest=400
. I want the BoxView
to fill the screen space. How can it be done?
解决方案
Use Grid
and set <RowDefinition Height="*" />
.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<BoxView Grid.Row="0" BackgroundColor="Black" />
</Grid>
If you are using nested Grid
then set <RowDefinition Height="*" />
in the outermost Grid
. When you are setting Height and Width of BoxView
same as the Screen size, then it is obvious that BoxView will take all of the screen space. Hence outermost Grid
will have only 1 Row. Now if you want to show other UI elements on the same Page then you will have to hide the BoxView
that was covering the UI. Hence outermost Grid
will contain 1 Row, that will be used to show either BoxView
or other UI elements. Just like this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<BoxView Grid.Row="0" BackgroundColor="Black" IsVisible="True"/>
<StackLayout Grid.Row="0" IsVisible="False">
<Label Text="Hello"/>
</StackLayout>
</Grid>
Note that you can also use nested Grid
instead of StackLayout
and organize your elements as per your choice.
If you want to add elements inside a BoxView
just like Cards then use Frame
instead.
推荐阅读
- node.js - 如何使用 tsc-watch (或类似的)来监视所有文件的更改、重新编译并将它们复制到我的 build/dist 文件夹中?
- c# - 在c#中将字节保存到临时文件中
- ruby-on-rails - 使用 RailsEventStore 仅订阅单个流
- java - 使用 Hibernate 将 SQL 的结果映射到字段
- ios - 在 iOS 上安装多种风格时,Firebase 动态链接无法打开正确的应用程序
- apache-kafka - 如何访问 flume-to-kafka 管道中的完整数据集?
- css - 我如何将 CSS 应用于 VAADIN 8 中的组件
- javascript - 按类名保存/加载复选框状态
- java - Android Studio - 尝试使用位于自定义 xml 文件中的代码更改 TextView 属性时应用程序崩溃
- javascript - Lodash.get 等价于 Ramda