首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"Sequence contains elements“错误

"Sequence contains elements“错误
EN

Stack Overflow用户
提问于 2017-06-19 21:44:56
回答 5查看 5.5K关注 0票数 3

在一个简单的xaml表单中,我得到了错误"Sequence contains no elements“。我对Xamarin表单相当陌生,所以请容忍我。

有什么想法吗?

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="CRM.Views.CustomerItem" Title="Customer Info">

<ContentPage.Content>

    <StackLayout Padding="10" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Label Text="Name" Grid.Row="0" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
            <Entry Text="{Binding CustName}" Grid.Row="0" Grid.Column="1"/>
            <Label Text="Surname" Grid.Row="1" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
            <Entry Text="{Binding CustSurname}" Grid.Row="1" Grid.Column="1"/>
            <Label Text="Address" Grid.Row="2" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
            <Entry Text="{Binding Address}" Grid.Row="2" Grid.Column="1"/>
            <Label Text="PhoneNumber" Grid.Row="3" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
            <Entry Text="{Binding PhoneNumber}" Grid.Row="3" Grid.Column="1"/>
        </Grid>
    </StackLayout>

    <Button Text="Save" HorizontalOptions="FillAndExpand" BackgroundColor="Blue" TextColor="White" Clicked="Save_Clicked"></Button>
    <Button Text="Cancel" HorizontalOptions="FillAndExpand" BackgroundColor="Red" TextColor="White" Clicked="Cancel_Clicked"></Button>

</ContentPage.Content>

EN

回答 5

Stack Overflow用户

发布于 2017-10-20 22:17:28

始终确保ContentPage.Content只有一个布局控件,如StackLayout或Grid等,以及它们内部的所有其他控件。

代码语言:javascript
复制
<ContentPage.Content>
   <StackLayout>
       <!-- all controls go here -->
   </StackLayout>
</ContentPage.Content>

这将会解决这个问题

票数 8
EN

Stack Overflow用户

发布于 2017-06-19 21:54:27

按钮很好,但是网格没有定义行,但是您使用的是Grid.Row="0“。由于序列中没有行,因此它会显示"Sequence contains no elements“。

尝试添加行定义

代码语言:javascript
复制
<StackLayout Padding="10" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

    <Grid>
        <Grid.RowDefinitions>
             <RowDefinition Height="100" />
             <RowDefinition Height="100" />
             <RowDefinition Height="100" />
             <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Label Text="Name" Grid.Row="0" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
        <Entry Text="{Binding CustName}" Grid.Row="0" Grid.Column="1"/>
        <Label Text="Surname" Grid.Row="1" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
        <Entry Text="{Binding CustSurname}" Grid.Row="1" Grid.Column="1"/>
        <Label Text="Address" Grid.Row="2" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
        <Entry Text="{Binding Address}" Grid.Row="2" Grid.Column="1"/>
        <Label Text="PhoneNumber" Grid.Row="3" Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center"></Label>
        <Entry Text="{Binding PhoneNumber}" Grid.Row="3" Grid.Column="1"/>
    </Grid>
</StackLayout>

<Button Text="Save" HorizontalOptions="FillAndExpand" BackgroundColor="Blue" TextColor="White" Clicked="Save_Clicked"></Button>
<Button Text="Cancel" HorizontalOptions="FillAndExpand" BackgroundColor="Red" TextColor="White" Clicked="Cancel_Clicked"></Button>

票数 1
EN

Stack Overflow用户

发布于 2017-06-19 21:53:04

代码语言:javascript
复制
You Must be Create Rows and Columns Both...

<Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="2*" />
        <RowDefinition Height="*" />
        <RowDefinition Height="200" />
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
    </Grid>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44632302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档