【发布时间】:2020-06-30 03:49:24
【问题描述】:
我查看了我能找到的所有关于此的帖子,但没有一个以我理解的方式回答这个问题。我正在慢慢尝试构建一个跟踪纸牌游戏生活的应用程序。现在,我只是想让生命总数显示出来,这样我就可以定义我的方法,让两个递增和递减按钮完成它们的工作。我以前在后端工作过,所以我知道如何让按钮来做他们的事情,但我不明白为什么我的生活总字符串没有显示为文本。
这里是xml代码:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Notes.MainPage">
<StackLayout Margin="10,35,10,10">
<Label
Text="{Binding lifeTotalString}"
FontSize="30"
HorizontalOptions="Center"
FontAttributes="Bold"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Text="-"
Clicked="btnDecrement" />
<Button Grid.Column="1"
Text="+"
Clicked="btnIncrement"/>
</Grid>
</StackLayout>
下面是代码
namespace Notes
{
public partial class MainPage : ContentPage
{
int lifeTotal = 20;
public MainPage()
{
InitializeComponent();
string lifeTotalString = lifeTotal.ToString();
}
void btnDecrement(object sender, EventArgs e)
{
}
void btnIncrement(object sender, EventArgs e)
{
}
}
}
【问题讨论】:
-
你试过我的解决方案了吗?
标签: c# android xamarin data-binding