我是 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/