這是我第一次使用 C# 在移動應用程式 (Xamarin) 中開始編碼,當我單擊它時,我試圖創建按鈕,出現帶有一些資訊的訊息,我在 .xaml 檔案中撰寫了這段代碼:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App1.MainPage">
<ContentPage.Content>
<StackLayout>
<Button Text="click Me"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
Clicked="OnButtonClicked"/>
<Label x:Name ="lblMessage" FontSize="Large"></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>
我在 c# 檔案中寫了這個:
namespace App1
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void OnButtonClicked(object sender, EventArgs e)
{
lblMessage.Text = "save";
}
}
}
我在 c# 檔案中的lblMessage變數中遇到的錯誤是:
The name 'lblMessage' does not exist in the current context
我是從 youtube 頻道做的,這正是他所做的,但它與他一起作業并且給了我一個錯誤,有什么想法或幫助嗎?
uj5u.com熱心網友回復:
1.首先清理你的專案
2.重建它,將您的 XAML 檔案屬性(構建操作)從 Embedded Resource 更改為 C# 編譯器,重建您的專案(將引發錯誤)。
3.將您的 XAML 檔案屬性切換回 Embedded Resource,Rebuild。
請參閱此鏈接:https ://forums.xamarin.com/discussion/96447/the-name-initializecomponent-does-not-exist-in-the-current-context
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/432724.html
標籤:C# xamarin xamarin.forms xamarin.android xamarin.ios
