我是 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!");
}
}
}
图片
最佳答案
1.清理你的项目
2.重建它,将您的 XAML 文件属性(构建操作)从嵌入式资源更改为编译,重建您的项目(会抛出错误)。
3.将您的 XAML 文件属性切换回 Embedded Resource,Rebuild。
关于c# - Xamarin。当前上下文中不存在名称“authorEntry”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49592370/