Steps:
- Create a blank windows store 8.1 app.
- Add a WebView and RichEditBox in xaml of the page.
- <WebView Height="500" x:Name="webView" Loaded="webView_Loaded" NavigationCompleted="webView_NavigationCompleted" Width="500" HorizontalAlignment="Left" />
- <RichEditBox x:Name="richEditBox" Width="500" Height="500" HorizontalAlignment="Right" />
- I have tried this for html string as it’s is easy to add script in html.
- public static string GetHTML()
- {
- return "<html>" +
- "<head>" +
- "<script type='text/javascript'>" +
- "function select_body() " +
- "{" +
- "var range = document.body.createTextRange(); " +
- "range.select();" +
- "}" +
- "</script>" +
- "<body>" +
- "<h1>My First Heading</h1>" +
- "<p>My first paragraph.</p>" +
- "</body></head></html>";
- }
- Now navigate webview to the html string.
- private void webView_Loaded(object sender, RoutedEventArgs e)
- {
- webView.NavigateToString(GetHTML());
- }
- When the webPage is navigated we can notify a script and get rtf from webview.
private async void webView_NavigationCompleted(WebView sender,
- WebViewNavigationCompletedEventArgs args)
- {
- await webView.InvokeScriptAsync("select_body", null);
- DataPackage p = await webView.CaptureSelectedContentToDataPackageAsync();
- string rtf = await p.GetView().GetRtfAsync();
- richEditBox.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, rtf);
- }


Sonu ChaudharyPosted Feb 25, 2016, 6:34 AM
good one!
Shubham KumarPosted Jan 21, 2016, 3:57 AM
nice share