c# - Xamarin。当前上下文中不存在名称“authorEntry”

标签 c# forms xaml xamarin

我是 Xamarin 的新手。我想将信息添加到 Book 类,然后使用 displayalert() 方法显示信息及其工作。但是为什么会出错?希望你们能帮我解决这个问题。先谢谢你们了。

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!");
        }
    }
}

错误列表 enter image description here

图片

enter image description here

最佳答案

1.清理你的项目

2.重建它,将您的 XAML 文件属性(构建操作)从嵌入式资源更改为编译,重建您的项目(会抛出错误)。

3.将您的 XAML 文件属性切换回 Embedded Resource,Rebuild。

引用这个链接: https://forums.xamarin.com/discussion/96447/the-name-initializecomponent-does-not-exist-in-the-current-context

关于c# - Xamarin。当前上下文中不存在名称“authorEntry”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49592370/

相关文章:

用于提交基于多个变量重定向的表单的 JavaScript

javascript - 访问类 ="input-append"的元素

xaml - 更改 VisualState 中的值

c# - 使用C#获取两个字母(AE)之间的字母(ABCDE)

c# - 有效地从大型列表中删除重复项?

javascript - 将列表与在线数据库进行比较,提交后使用 JavaScript

performance - 图像需要很长时间才能加载 WinRT XAML

c# - 已为应用付费的用户的应用内购买

c# - 查看 wcf 服务发回的数据大小

c# - ToDouble() 不工作?