mrbengi mrbengi - 1 year ago 117
Android Question

How to add a button in Xamarin.Forms?

I'm new to Xamarin.

Could you write me the code for adding a button in Xamarin.Forms?

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


Above snippet will create a Page with a Button having text Hello World centered horizontally and vertically in the page and set it as the LaunchPage of the application. This is an example of how you can have button programmatically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download