Skip to content

Instantly share code, notes, and snippets.

@hprez21
Last active March 16, 2017 16:41
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 hprez21/f9738980e95774a0eaaa93150123db30 to your computer and use it in GitHub Desktop.
Save hprez21/f9738980e95774a0eaaa93150123db30 to your computer and use it in GitHub Desktop.
Xamarin.Forms: Cargar un archivo html a un WebView.Source (Tomado de la documentación oficial)
//@param1 = Clase que contiene el método LoadHTMLFileFromResource
//@param2 = Archivo html, partiendo de la estructura del proyecto, por ejemplo: Recetas.test.html
//Ejemplo completo en https://github.com/hprez21/Recetas-Xamarin-Forms
HtmlWebViewSource LoadHTMLFileFromResource()
{
var source = new HtmlWebViewSource();
// Carga el archivo HTML embebido como un recurso en el PCL
var assembly = typeof(@parm1).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("@param2");
using (var reader = new StreamReader(stream))
{
source.Html = reader.ReadToEnd();
}
return source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment