![](/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.