所以我是 Xamarin Forms 的新手,我发现了两种添加按钮的方法:
1.在.xaml文件中声明按钮
<!-- <Button Text="Click Me!"
Clicked="OnButtonClicked" VerticalOptions="CenterAndExpand" />-->
Run Code Online (Sandbox Code Playgroud)
和 .xaml.cs 文件
public void OnButtonClicked(object sender, EventArgs args)
{
count++;
label.Text =
String.Format("{0} click{1}!", count, count == 1 ? "" : "s");
Run Code Online (Sandbox Code Playgroud)
仅在 .xaml.cs 文件中声明按钮
using System;
using Xamarin.Forms;
namespace FormsGallery
{
class ButtonDemoPage : ContentPage
{
Label label;
int clickTotal = 0;
public ButtonDemoPage()
{
Label header = new Label
{
Text = "Button",
Font = Font.BoldSystemFontOfSize(50),
HorizontalOptions = LayoutOptions.Center
};
Button button = new Button …Run Code Online (Sandbox Code Playgroud)