Skip to content

Instantly share code, notes, and snippets.

@Pujolsluis
Last active June 24, 2020 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pujolsluis/942720123e07df1046cb5ed695dd0024 to your computer and use it in GitHub Desktop.
Save Pujolsluis/942720123e07df1046cb5ed695dd0024 to your computer and use it in GitHub Desktop.
Device open's the provided PDF URL with the Device Browser, and style it to look like it's inside the app. making use of Xamarin.Essentials
using Xamarin.Essentials;
public Task OpenPdf(string url, BrowserLaunchOptions? browserLaunchOptions = null)
{
return MainThread.InvokeOnMainThreadAsync(() =>
{
var currentTheme = (BaseTheme?)Application.Current?.Resources;
if (currentTheme != null)
{
browserLaunchOptions ??= new Xamarin.Essentials.BrowserLaunchOptions
{
PreferredControlColor = currentTheme.NavigationBarTextColor,
PreferredToolbarColor = currentTheme.NavigationBarBackgroundColor,
Flags = BrowserLaunchFlags.PresentAsFormSheet
};
}
return Browser.OpenAsync(url, browserLaunchOptions);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment