![](/img/trans.png)
[英]Xamarin can't see objects in MainPage.xaml from MainPage.xaml.cs
[英]can't see objects in MainPage.xaml.cs -xamarin-C#
不能从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)
{
}
}
}
像这样在“内容”页面内容中添加堆栈布局。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.