小编man*_*sta的帖子

在 Xamarin Forms 中添加按钮的最佳方法是什么?

所以我是 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)
  1. 仅在 .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)

c# xaml xamarin xamarin.forms visual-studio-2017

2
推荐指数
1
解决办法
4490
查看次数

标签 统计

c# ×1

visual-studio-2017 ×1

xamarin ×1

xamarin.forms ×1

xaml ×1