在我的MainPage.xaml中看不到标签或按钮 错误“名称greetinglabel在当前内容中不存在”
MainPage.xaml代码
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:hello"
x:Class="hello.MainPage">
<StackLayout>
<Label x:Name="greetinglabel"
Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="Center" />
<Entry x:Name="nameEntry"
Placeholder="write your name"/>
<Button Text="say hello"
Clicked="Button_Clicked"/>
</StackLayout>
MainPage.xaml.cs代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace hello
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
void Button_Clicked(object sender, EventArgs e)
{
}
}
}
答案 0 :(得分:0)
像这样在“内容”页面内容中添加堆栈布局。
<ContentPage.Content>
<StackLayout>
<Label x:Name="greetinglabel"
Text="Welcome to Xamarin.Forms!"
HorizontalOptions="Center"
VerticalOptions="Center" />
<Entry x:Name="nameEntry"
Placeholder="write your name"/>
<Button Text="say hello"
Clicked="Button_Clicked"/>
</StackLayout>
</ContentPage.Content>