Bengi Besceli
Bengi Besceli

Reputation: 3748

How to redirect in Xamarin.Forms

I use Xamarin and debug on an Android device.
How to redirect an url in Xamarin.Forms?

I'm trying this in default page load.

Upvotes: 2

Views: 4504

Answers (1)

Luis Beltran
Luis Beltran

Reputation: 1704

You can use Device.OpenUri to open the URL in the mobile browser:

Device.OpenUri(new Uri("http://xamarin.com"));

Here is a sample implementation:

using System;
using Xamarin.Forms;

namespace Example
{
    class MyPage : ContentPage
    {

        public MyPage()
        {
            Button button = new Button
            {
                Text = "Open URL",
                Font = Font.SystemFontOfSize(NamedSize.Large),
                BorderWidth = 1,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            button.Clicked += OnButtonClicked;

            this.Content = new StackLayout
            {
                Children = {
                    button
                }
            };
        }

        void OnButtonClicked(object sender, EventArgs e)
        {
            Device.OpenUri(new Uri("http://xamarin.com"));
        }
    }
}

Upvotes: 3

Related Questions