android - 在 Xamarin 中处理按钮单击事件

标签 android xamarin

我是 Xamarin 的新手,英语不是很好,无法阅读相关的手册。
有人可以告诉我如何在 Xamarin 的代码隐藏中处理此按钮的点击事件方法吗?

public class App : Application
{
    public App ()
    {
        // The root page of your application
        MainPage =new ContentPage{
            Content= new Button{Text="Click me",BackgroundColor=Color.Black,HorizontalOptions=LayoutOptions.Center,VerticalOptions=LayoutOptions.Center,TextColor=Color.White}
    };
}

最佳答案

public class App : Application
{
    public App ()
    {
        // The root page of your application
        MainPage =new LaunchPage();
    }
}
public class LaunchPage:ContentPage
{
    public LaunchPage ()
    {
        var button=new Button{Text="Hello World",BackgroundColor=Color.Black,HorizontalOptions=LayoutOptions.Center,VerticalOptions=LayoutOptions.Center,TextColor=Color.White};
        button.Clicked += ButtonClicked;
        Content = button;
    }
    void ButtonClicked(object sender, EventArgs args)
    {
        DisplayAlert ("Button Clicked", "This Button has been clicked", "OK");
    }
}

关于android - 在 Xamarin 中处理按钮单击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37045505/

相关文章:

c# - MobileServiceClientWhere() 语法

c# - "System.IO.FileNotFoundException: Could not load assembly ' Xamarin.Android.Support.v13 '"替换为支持库 v4 后

android - 测量可绘制对象的大小(内存)

android - 带有自定义适配器的 ListView 给出空指针异常

php - Android 到 MYSQL 使用 php

android - 我可以在 xamarin android 应用程序中设置设备语言/文化吗

c# - 如何在带有 ReactiveUI 和 Xamarin Forms 的 ListView ItemTemplate 中使用 ViewModelViewHost?

c# - Epson TM-U220 USB 打印错误

xamarin.ios - xamarin VisualStudio for ios 中没有附加设备

java - 如何删除支持库 (appcompat_v7) [Eclipse]