XAML错误:在xmlns中找不到类型RelativePanel

时间:2018-01-18 23:22:52

标签: xaml exception-handling xamarin.forms

我为xamarin.forms交叉平台应用程序编写了XAML代码,在xmlns中找不到类型RelativePanel。

<?xml version="1.0" encoding="utf-8" ?>
   <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:App2"
         x:Class="App2.MainPage"
         BackgroundColor="White">
<StackLayout  >
    <Label Text="Browse Files" 
       VerticalOptions="Start" 
       HorizontalOptions="CenterAndExpand"
       TextColor="Black"
       FontAttributes="Bold"
       HorizontalTextAlignment="Center"
       />

    <RelativePanel HorizontalAlignment="Center"  
        Margin="0,10,0,0">
        <Entry 
        Text ="LOAD FILES"
           x:Name="files"
           BackgroundColor="Black">

            <Entry.WidthRequest>
                <OnPlatform x:TypeArguments="x:Double">
                    <On Platform ="iOS">80</On>
                    <On Platform ="Android,Windows">70</On>
                </OnPlatform>
           </Entry.WidthRequest>

           <Entry.HeightRequest>
                <OnPlatform x:TypeArguments="x:Double">
                    <On Platform="iOS">80</On>
                    <On Platform="Android,Windows">70</On>
                </OnPlatform>
            </Entry.HeightRequest>

        </Entry>
        <Button Text="...."
         VerticalOptions="End"
         HorizontalOptions="End"
            x:Name="Button1"/>

    </RelativePanel>

    <RelativePanel HorizontalAlignment="Center"  
        Margin="0,10,0,0">

        <Button x:Name="processbtn" Content="Process"  
            Height="35" Width="65" Click="processbtn_Click"/>

        <Button x:Name="cancelbtn" Content="Exit"  
            Height="35" Width="65" Margin="10,0,0,0"  
            RelativePanel.RightOf="loginbtn" Click="cancelbtn_Click"/>

    </RelativePanel>
    </StackLayout>
    </ContentPage>

未处理的例外:

  

Xamarin.Forms.Xaml.XamlParseException:位置16:10。在xmlns http://xamarin.com/schemas/2014/forms中找不到类型RelativePanel

当我删除relativePanel时,内容和高度会发生异常。

1 个答案:

答案 0 :(得分:2)

  

RelativePanel不是受支持的Xamarin Forms控件。

相反,您应该使用RelativeLayout

RelativeLayout可用于相对于整体布局或其他两个视图在屏幕上定位视图。

所以,这里有一点样本:

<RelativeLayout>
    <BoxView Color="Gray" HeightRequest="100"
        RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" />
    <Button BorderRadius="35" x:Name="imageCircleBack"
        BackgroundColor="Maroon" HeightRequest="70" WidthRequest="70" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width, Factor=.5, Constant = -35}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Factor=0, Property=Y, Constant=70}" />
    <Button BorderRadius="30" BackgroundColor="Red" HeightRequest="60"
        WidthRequest="60" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToView, ElementName=imageCircleBack, Property=X, Factor=1,Constant=5}" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Factor=0, Property=Y, Constant=75}" />
    <Label Text="User Name" FontAttributes="Bold" FontSize="26"
        HorizontalTextAlignment="Center" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=140}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" />
    <Entry Text="Bio + Hashtags" TextColor="White" BackgroundColor="Maroon"
        RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=180}" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" />
    <RelativeLayout BackgroundColor="White" RelativeLayout.YConstraint="
        {ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=220}" HeightRequest="60" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" >
        <BoxView BackgroundColor="Black" WidthRequest="50"
            HeightRequest="50" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=5}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=5}" />
        <BoxView BackgroundColor="Maroon" WidthRequest="50"
            HeightRequest="50" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=5}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=}" />
        <Label FontSize="14" TextColor="Black" Text="Accent Color"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=20}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=60}" />
        <Label FontSize="14" TextColor="Black" Text="Primary Color"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=20}" RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=55}" />
    </RelativeLayout>

有关详细信息,请参阅:RelativeLayout documentation