处理Xamarin中的按钮单击事件

时间:2016-05-05 08:03:39

标签: android xamarin

我是Xamarin的新人,在阅读相关的mannuels方面不太擅长英语。
有人可以告诉我如何在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}
    };
}

1 个答案:

答案 0 :(得分:3)

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");
    }
}