简体   繁体   English

Xamarin:“序列不包含匹配元素”异常

[英]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:我正在学习 Xamarin forms,在尝试在线教程时,我尝试了以下相对布局:

<?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这是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'每次调试代码时,都会收到此错误: 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.如您所见,此处仅更改Property=Height而不是Property=height和 Width 属性。 This should fix your problem.这应该可以解决您的问题。

Your error seems to be a typo.你的错误似乎是一个错字。 Width and Height are lowercase. WidthHeight是小写的。

    <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.-希望这可以帮助。-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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