简体   繁体   中英

Xamarin: 'Sequence contains no matching element' Exception

I am learning Xamarin forms, and while trying an online tutorial, I tried the following for Relative Layout:

<?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:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="HelloWorldNew.RelativeLayout">
    <ContentPage.Content>
        <RelativeLayout>
            <BoxView Color="green" RelativeLayout.WidthConstraint="{ConstraintExpression
                Type=RelativeToParent,
                Property=width,
                Factor=1}"
                     
                RelativeLayout.HeightConstraint="{ConstraintExpression
                Type=RelativeToParent,
                Property=height,
                Factor=0.3}" />
        </RelativeLayout>
        
    </ContentPage.Content>
</ContentPage>

Here is RelativeLayout.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace HelloWorldNew
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class RelativeLayout : ContentPage
    {
        public RelativeLayout()
        {
            InitializeComponent();
        }
    }
}

Every time I debug the code, I get this error: System.InvalidOperationException: 'Sequence contains no matching element'

Any ideas where I went wrong?

<?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:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="HelloWorldNew.RelativeLayout">
    <ContentPage.Content>
        <RelativeLayout>
            <BoxView Color="green" RelativeLayout.WidthConstraint="{ConstraintExpression
                Type=RelativeToParent,
                Property=Width,
                Factor=1}"
                     
                RelativeLayout.HeightConstraint="{ConstraintExpression
                Type=RelativeToParent,
                Property=Height,
                Factor=0.3}" />
        </RelativeLayout>
        
    </ContentPage.Content>
</ContentPage> 

As you can see only change here is Property=Height not Property=height and respectively for the Width property. This should fix your problem.

Your error seems to be a typo. Width and Height are lowercase.

    <RelativeLayout>
        <BoxView Color="green" RelativeLayout.WidthConstraint="{ConstraintExpression
            Type=RelativeToParent,
            Property=Width,
            Factor=1}"
                 
            RelativeLayout.HeightConstraint="{ConstraintExpression
            Type=RelativeToParent,
            Property=Height,
            Factor=0.3}" />
    </RelativeLayout>

Hope this helps.-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM