[英]Get value of an int Variable from MainPage.xaml.cs file to MainPage.xaml file in Xamarin
[英]Xamarin can't see objects in MainPage.xaml from MainPage.xaml.cs
我在 MainPage.xaml.cs 中看不到我的標簽或按鈕。 如果我在 MainPage.xaml.cs 中嘗試這一行
valueLabel.text = "你好";
在錯誤列表中,當前內容中不存在錯誤值標簽
我已經嘗試了幾天來解決此問題,但找不到解決方案,希望您能幫助我
我的代碼:
我的主頁.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"
xmlns:local="clr-namespace:knap_der_tæller_op"
x:Class="knap_der_tæller_op.MainPage">
<Label x:Name="valueLabel"
Text="A simple Label"
Font="Large"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Button Text="Click Me!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"
Clicked="OnButtonClicked" />
</ContentPage>
我的 MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace knap_der_tæller_op
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = this;
}
void OnButtonClicked(object sender, EventArgs args)
{
}
public string Labettext { get; set; } = "Hej med dig" ;
}
}
您是否嘗試將內容放入<ContentPage.Content></ContentPage.Content>
你唯一需要做的就是重建你的項目,問題就解決了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.