private async void SelectedListItem(object sender, SelectionChangedEventArgs e) { var selectedItems = ListBoxUrls.SelectedItems; if (selectedItems.Count > 0) { // Display text of first item selected. //WebViewBrowse.NavigateToString(selectedItems[0].ToString()); if (!selectedItems[0].ToString().Contains("http")) { TextBoxUrl.Text = currentRootUrl + selectedItems[0].ToString(); } else { TextBoxUrl.Text = selectedItems[0].ToString(); currentRootUrl = TextBoxUrl.Text; } ListBoxUrls.ItemsSource = await client.GetHrefLinksAsync(TextBoxUrl.Text); NavigateThroughSurferLite(TextBoxUrl.Text); } else { // Display default string. WebViewBrowse.NavigateToString("Empty selected from ListBox"); } }
public BrowserStart() { this.InitializeComponent(); // Initialize the reference object with a service try{ client = new ServiceReferenceSurferliteAzureServer.ServiceSurferliteClient(); } catch { WebViewBrowse.NavigateToString("Can't connect to the SurferLite server"); } // Source Code view is not visible on start of page. TextBlockSource.Visibility = Visibility.Collapsed; }
/// <summary> /// This method is async method and is used to display page through SurferLite Service /// </summary> /// <param name="URLString">The URL in string which you want to display in WebViewBrowse</param> private async void NavigateThroughSurferLite(string URLString) { try { Uri URL = new Uri(URLString); ProgressRingLoad.IsActive = true; //Although Service Contract says GetHtml(URL) returns stream. It automatically is byte[]. //XXXXXX: Stream pullStream = await client.GetHtmlAsync(URL); byte[] pullStream = await client.GetHtmlAsync(URL); // Update total data dataSize += pullStream.Length; // Displaying size of byte[] got from service TextBlockSize.Text = pullStream.Length.ToString() + " B"; // Decompressing pullStream to get actual decompressed data string result = DecompressBytes(pullStream); // To view in Html Source TextBlockSource.Text = result; // result is ready and is displayed in webview WebViewBrowse.NavigateToString(result); } catch (Exception e) { // There is some error. This needs modification so Exception is exact WebViewBrowse.NavigateToString(e.ToString()); } ProgressRingLoad.IsActive = false; }