mrbengi mrbengi - 3 months ago 19
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
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.

Comments