[英]Why FirstOrDefault get this exception? Sequence contains no matching element exception
[英]Xamarin: 'Sequence contains no matching element' Exception
我正在学习 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>
这是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();
}
}
}
每次调试代码时,都会收到此错误: System.InvalidOperationException: 'Sequence contains no matching element'
有什么想法我哪里出错了吗?
<?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>
如您所见,此处仅更改Property=Height
而不是Property=height
和 Width 属性。 这应该可以解决您的问题。
你的错误似乎是一个错字。 Width
和Height
是小写的。
<RelativeLayout>
<BoxView Color="green" RelativeLayout.WidthConstraint="{ConstraintExpression
Type=RelativeToParent,
Property=Width,
Factor=1}"
RelativeLayout.HeightConstraint="{ConstraintExpression
Type=RelativeToParent,
Property=Height,
Factor=0.3}" />
</RelativeLayout>
希望这可以帮助。-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.