我正在尝试将本机Xamarin.iOS转换为Xamarin.Forms,并遇到一个简单的布局问题。我想要实现的是一个像红色网格这样的菜单:
因此,每个Gridelement的高度应等于宽度,但我得到的只是这个宽度:
我的Xaml看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<mvvm:BaseContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mvvm="clr-namespace:SharpLibrary.Forms.Source.MVVM;assembly=SharpLibrary.Forms"
xmlns:cc="clr-namespace:Gorilla.Forms.Source.UI.CustomControls"
x:Class="Gorilla.Forms.Source.UI.Guest.GuestMainPage">
<ContentPage.Content>
<RelativeLayout
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
>
<Image Style="{StaticResource StandardBackgroundImage}" />
<ScrollView
RelativeLayout.WidthConstraint = "{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.HeightConstraint = "{ConstraintExpression Type=RelativeToParent, Property=Height}"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<cc:GridMenuItem
x:Name="testBox"
Grid.Row="0" Grid.Column="0"
BackgroundColor="Red"
Title="Test"
Icon="Text" />
<Frame
x:Name="testFrame"
Grid.Row="0" Grid.Column="1"
BackgroundColor="Gray"
HeightRequest="{Binding WidthRequest}">
<Label Text="gdjfgzhg" />
</Frame>
</Grid>
</ScrollView>
</RelativeLayout>
</ContentPage.Content>
</mvvm:BaseContentPage>
我无法弄清楚我做错了什么,也找到了一些人们想要实现与我相同的目标的Threads,但它并没有达到我的期望。
希望有人知道答案
参考方案
我建议您根据需要使用以下布局:
<!-- No need to use AbsoluteLayout or Constraint-->
<Grid>
<Image Style="{StaticResource StandardBackgroundImage}" />
<ScrollView>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- Width responsive dependending on Screen, and Width (not WidthRequest) equals (Binding with source equals to itself)-->
<cc:GridMenuItem x:Name="testBox"
Grid.Row="0" Grid.Column="0"
HeightRequest="{Binding Width, Source={x:Reference testBox}}"
BackgroundColor="Red"
Title="Test"
Icon="Text" />
<Frame x:Name="testFrame"
Grid.Row="0" Grid.Column="1"
BackgroundColor="Gray"
HeightRequest="{Binding Width, Source={x:Reference testFrame}}">
<Label Text="gdjfgzhg" />
</Frame>
</Grid>
<ScrollView>
</Grid>
如何在XAML [Xamarin.Forms]中使用String以外的Type设置自定义属性值 - c#在XAML的Xamarin.Forms中,您可以编写如下内容:<Entry Keyboard="Plain" /> 我调查了Entry类,并且Keyboard属性的类型为Xamarin.Forms.Keyboard。但是,如果我创建自己的自定义ContentView并在其中写入如下内容: public static reado…
jQuery不起作用 - php我正在使用带有ajax的jquery。有时,给出错误$未定义。这是我的代码:<script language="javascript" type="text/javascript"> var base_path="<? echo $this->baseUrl().'/…
Div单击与单选按钮相同吗? - php有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date…
故障排除“警告:session_start():无法发送会话高速缓存限制器-标头已发送” - php我收到警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送(错误输出开始如果我将表单数据提交到其他文件进行处理,则可以正常工作。但是,如果我将表单数据提交到同一页面,则会出现此错误。请建议<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0…
CodeIgniter更新查询被执行两次 - php我正在使用CodeIgniter 2.2。每次访问页面时,我都必须用+1更新数据库。代码可以工作,但是每次都会增加+2。示例:如果是total views=2,则在单击页面后total views应该是3,但是数据库中的值是4。我确定我在控制器中仅调用一次模型add_one_to_view_image。控制者 function view(){ $view_i…