Xamarin. The name 'authorEntry does not exist in the current context

懵懂的女人 提交于 2021-02-10 04:49:16

问题


I'm new in Xamarin. I want to add information to Book class then display information using displayalert() method and its worked. But Why got an error? Hope you guys can help me solve this problem.Thank you in advance.

NewBookPage.xaml

<?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="Form.NewBookPage">
        <StackLayout Margin="10,10,10,0">

            <Entry x:Name="nameEntry"
                Placeholder="name of the book"/>

            <Entry x:Name="authorEntry"
                   Placeholder="name of the author"/>

        <Button Text="save"
               Clicked="Button_Clicked" />

    </StackLayout>
</ContentPage>

NewBookPage.xaml.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 Form
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class NewBookPage : ContentPage
    {
        public NewBookPage ()
        {
            InitializeComponent ();
        }

        private void Button_Clicked(object sender, EventArgs e)
        {
            Book book = new Book()
            {
                Name =  nameEntry.Text,
                Author = authorEntry.Text

            };
            DisplayAlert("Success",book.Name+"/"+book.Author, "great!");
        }
    }
}

Error List

Image


回答1:


1.Clean your project

2.Rebuild it, change your XAML file properties (Build Action) from Embedded Resource to Compile, Rebuild your project (will throw errors).

3.switch back your XAML file properties to Embedded Resource, Rebuild.

Refer to this link: https://forums.xamarin.com/discussion/96447/the-name-initializecomponent-does-not-exist-in-the-current-context



来源:https://stackoverflow.com/questions/49592370/xamarin-the-name-authorentry-does-not-exist-in-the-current-context

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!