↑ Return to Top
<
html
>
head
script
type
=
'text/javascript'
></
</
body
div
id
"ContentPlaceHolder"
WebView
Name
"webView"
Source
"ms-appx-web:///Assets/HtmlPageHolder.htm"
/>
Button
Grid.Row
"1"
Grid.Column
Command
"{Binding GenerateHtmlPageCommand}"
CommandParameter
"{Binding ElementName=webView}"
HorizontalAlignment
"Center"
VerticalAlignment
"Top"
Height
"100"
Style
"{StaticResource PreviewHtmlButtonStyle}"
IsEnabled
"{Binding Path=IsGenerateHtmlPageButtonEnabled, Mode=TwoWay}"
public
async
static
Task<
string
> getBase64ImageString(IStorageFile image)
{
base64ImageString =
.Empty;
try
IRandomAccessStream readStream = await image.OpenAsync(FileAccessMode.Read);
IInputStream inputStream = readStream.GetInputStreamAt(0);
DataReader dataReader =
new
DataReader(inputStream);
uint
numOfBytes = await dataReader.LoadAsync((
)readStream.Size);
byte
[] bytes =
[numOfBytes];
dataReader.ReadBytes(bytes);
base64ImageString = Convert.ToBase64String(bytes);
}
catch
(Exception ex)
WebViewUtils.LogException(ex);
return
base64ImageString;
GenerateHtmlContent(
headerText, IList<WebViewImage> webViewImages)
htmlPage =
null
;
if
(webViewImages !=
)
StringBuilder sb =
StringBuilder();
(headerText.Length > 0)
sb.Append(
.Format(WebViewConstants.HTML_PARAGRAPH_TAG_NO_NEWLINE, headerText));
foreach
(WebViewImage webViewImage
in
webViewImages)
.Format(WebViewConstants.HTML_IMAGE_BASE64_TAG_NO_NEWLINE, webViewImage.Base64String));
htmlPage = sb.ToString();
htmlPage;
bool
InjectHtmlIntoPage(WebView webView,
htmlPageContent,
divElementId)
success =
false
"function addHtmlContentToDiv()"
);
"{"
.Format(
" var placeHolderElement = document.getElementById('{0}');"
, divElementId));
" if (placeHolderElement) {"
" placeHolderElement.innerHTML ='"
sb.Append(htmlPageContent);
"';"
" }"
"}"
script = sb.ToString();
webView.InvokeScript(
"eval"
,
[] { script });
[] {
"addHtmlContentToDiv()"
});
true
success;
Naomi N edited Revision 18. Comment: Very nice article!
Naomi N edited Revision 16. Comment: Minor edit
Sachin S edited Revision 15. Comment: Fixed typo
Sachin S edited Revision 14. Comment: Corrected typo
Sachin S edited Revision 13. Comment: Finishing initial draft
Sachin S edited Revision 12. Comment: Updated Code
Sachin S edited Revision 11. Comment: Finishing initial draft
Sachin S edited Revision 10. Comment: Finishing initial draft
Sachin S edited Revision 9. Comment: Finishing initial draft
Sachin S edited Revision 8. Comment: Finishing initial draft
Naomi N edited Original. Comment: Minor correction
Sachin S edited Revision 1. Comment: Finishing initial draft
Sachin S edited Revision 2. Comment: Finishing initial draft