[英]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.