Alan2
Alan2

Reputation: 24572

How can I add a link to my Xamarin.Forms application so it opens a web page?

I know how to code the buttons, how to use Command but what I would like some advice on is if there's a way to open a web page from the C# code in my application? Is this something I need to do async and is there some function I can call that will do this that works in forms back-end code?

Upvotes: 0

Views: 185

Answers (1)

Arvind Chourasiya
Arvind Chourasiya

Reputation: 17422

This is would open a web page in your default browser

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

I don't think it should be async function in any way

If you want to write in as async download Xamarin.Essentials plugin and write it as

public async Task<bool> OpenBrowser(Uri uri)
 {
        return await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
 }

This method returns after the browser was launched and not necessarily closed by the user. The bool result indicates whether the launching was successful or not.

Read on learn.microsoft.com for more information.

Upvotes: 2

Related Questions