private void Show(object obj) { RadFlowDocument document = this.CreateDocument(); HtmlFormatProvider formatProvider = new HtmlFormatProvider(); string html = formatProvider.Export(document); WebBrowser browser = new WebBrowser(); browser.NavigateToString(html); Window window = new Window() { Width = 1000, Height = 350 }; window.Content = browser; window.Show(); }
/// <summary> /// Standard constructor for the tool window. /// </summary> public MarkdownPreviewToolWindow() : base(null) { this.Caption = "Markdown Preview"; this.BitmapResourceID = 301; this.BitmapIndex = 1; browser = new WebBrowser(); browser.NavigateToString(EmptyWindowHtml); browser.LoadCompleted += (sender, args) => { if (scrollBackTo.HasValue) { var document = browser.Document as mshtml.IHTMLDocument2; if (document != null) { var element = document.body as mshtml.IHTMLElement2; if (element != null) { element.scrollTop = scrollBackTo.Value; } } } scrollBackTo = null; }; }
private async void MyMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { MyMapView.Overlays.Items.Clear(); IEnumerable <KmlFeature> features = await(MyMapView.Map.Layers["kmlLayer"] as KmlLayer).HitTestAsync(MyMapView, e.Position); if (features.Count() > 0) { if (!string.IsNullOrWhiteSpace(features.FirstOrDefault().BalloonStyle.FormattedText)) { //Create WebBrowser to show the formatted text var browser = new System.Windows.Controls.WebBrowser(); browser.NavigateToString(features.FirstOrDefault().BalloonStyle.FormattedText); //Get the KmlPlacemark position var featurePosition = (features.FirstOrDefault() as KmlPlacemark).Extent; //Create ContentControl var cControl = new ContentControl() { Content = browser, MaxHeight = 500, MaxWidth = 450 }; //Add the ContentControl to MapView.Overlays MapView.SetViewOverlayAnchor(cControl, featurePosition.GetCenter()); MyMapView.Overlays.Items.Add(cControl); } } }
/// <summary> /// Standard constructor for the tool window. /// </summary> public MarkdownPreviewToolWindow() : base(null) { this.Caption = MarkdownSharp.Language.Message("DocumentPreview"); this.BitmapResourceID = 301; this.BitmapIndex = 1; //force WebBrowser into IE9 mode SetWebBrowserIE9DocMode(); browser = new WebBrowser(); browser.NavigateToString(MarkdownSharp.Language.Message("OpenUDNDocumentFileToSeePreview")); browser.LoadCompleted += (sender, args) => { if (scrollBackTo.HasValue) { var document = browser.Document as mshtml.IHTMLDocument2; if (document != null) { var element = document.body as mshtml.IHTMLElement2; if (element != null) { element.scrollTop = scrollBackTo.Value; } } } scrollBackTo = null; isLoading = false; }; browser.Navigating += new NavigatingCancelEventHandler(webBrowser_Navigating); }
/// <summary> /// Create Video Player. /// </summary> /// <param name="video"></param> private void SetVideo(string video) { var profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile(); if (profile != null) { var interfaceType = profile.NetworkAdapter.IanaInterfaceType; if (interfaceType == 71) { //Wifi _youTubeButton = new YouTubeButton {YouTubeID = _videoId}; _youTubeButton.Click += youTubeButton_Click; LayoutRoot.Children.Clear(); LayoutRoot.Children.Add(_youTubeButton); } else { //Other var web = new WebBrowser() { Height = 600, IsScriptEnabled = true }; web.NavigateToString(string.Format("<!doctype html>" + "<html><head><title></title></head><body style=background-color:black;>" + "<iframe height=\"600\" src=\"http://www.youtube.com/embed/{0}\" width=\"1000\"></iframe>" + "</body></html>", video)); LayoutRoot.Children.Clear(); LayoutRoot.Children.Add(web); } } }
private async void MyMapView_MapViewTapped(object sender, Esri.ArcGISRuntime.Controls.MapViewInputEventArgs e) { MyMapView.Overlays.Items.Clear(); IEnumerable<KmlFeature> features = await (MyMapView.Map.Layers["kmlLayer"] as KmlLayer).HitTestAsync(MyMapView, e.Position); if (features.Count() > 0) { if (!string.IsNullOrWhiteSpace(features.FirstOrDefault().BalloonStyle.FormattedText)) { //Create WebBrowser to show the formatted text var browser = new System.Windows.Controls.WebBrowser(); browser.NavigateToString(features.FirstOrDefault().BalloonStyle.FormattedText); //Get the KmlPlacemark position var featurePosition = (features.FirstOrDefault() as KmlPlacemark).Extent; //Create ContentControl var cControl = new ContentControl() { Content = browser, MaxHeight = 500, MaxWidth = 450 }; //Add the ContentControl to MapView.Overlays MapView.SetViewOverlayAnchor(cControl, featurePosition.GetCenter()); MyMapView.Overlays.Items.Add(cControl); } } }
/// <summary> /// Standard constructor for the tool window. /// </summary> public MarkdownPreviewToolWindow() : base(null) { this.Caption = "Markdown Preview"; this.BitmapResourceID = 301; this.BitmapIndex = 1; browser = new WebBrowser(); browser.NavigateToString(EmptyWindowHtml); browser.LoadCompleted += (sender, args) => { if (scrollBackTo.HasValue) { var document = browser.Document as mshtml.IHTMLDocument2; if (document != null) { var element = document.body as mshtml.IHTMLElement2; if (element != null) { element.scrollTop = scrollBackTo.Value; } } } scrollBackTo = null; }; browser.IsVisibleChanged += HandleBrowserIsVisibleChanged; browser.Navigating += (sender, args) => { if (this.path == null) { return; // current context unknown } if (args.Uri == null || args.Uri.HostNameType != UriHostNameType.Unknown || string.IsNullOrEmpty(args.Uri.LocalPath)) { return; // doesn't look like a relative uri } string documentName = new FileInfo(this.path).ResolveRelativePath( args.Uri.LocalPath.Replace('/', Path.DirectorySeparatorChar)); // If there is a file name but it doesn't exist and doesn't have an extension, try adding // ".md" (GitHub style target in a literal anchor link). if(documentName != null && !File.Exists(documentName) && Path.GetExtension(documentName).Length == 0) documentName += ".md"; if(documentName == null || !File.Exists(documentName)) { return; // relative path could not be resolved, or does not exist } VsShellUtilities.OpenDocument(this, documentName); args.Cancel = true; // open matching document }; }
/// <summary> /// /// </summary> /// <param name="o"></param> /// <param name="e"></param> public static void BindableSourcePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { _webBrowser = (WebBrowser)o; _webBrowser.NavigateToString((string)e.NewValue); // Object used for communication from JS -> WPF _webBrowser.ObjectForScripting = new HtmlInterop(); // for testing with an html source file: //webBrowser.Navigate(new Uri(@"file:///C:/Temp/test.html")); }
private void WebBrowserProperty(WebBrowser obj) { if (obj != null) { _browser = obj; _browser.NavigateToString(Properties.Resources.New); Doc = _browser.Document as HTMLDocument; if (Doc != null) { Doc.designMode = "On"; } } }
void HelpButton_Click(object sender, RoutedEventArgs e) { var vmdl = DataContext as ViewModel; if (vmdl != null && vmdl.HasHelpText) { var html = new WebBrowser(); var header = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body style=\"background:#FFFFE0;font-family: Verdana, Arial; font-size: 0.8em;\">"; var footer = "</body></html>"; html.NavigateToString(header + vmdl.HelpText + footer); var wnd = new Window(); wnd.Style = Application.Current.Resources["PopupWindow"] as Style; wnd.Title = vmdl.HelpCommand.Label; wnd.Content = html; wnd.Show(); } }
public static async Task DownloadHTMLAsync(SynchronizationContext sc, string url, WebBrowser toSet) { HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(url); string content = await response.Content.ReadAsStringAsync(); sc.Post(rawState => { string strToRemove = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">"; string parsedState = ((string)rawState).Replace(strToRemove, "").Trim(); HtmlDocument document = new HtmlDocument(); document.LoadHtml(parsedState); HtmlNode collection = document.GetElementbyId("fw-mainColumn"); toSet.NavigateToString(collection.InnerHtml); }, content); }
public void newWb(string url) { if (webBrowser != null) { webBrowser.LoadCompleted -= completed; webBrowser.Dispose(); gridwebBrowser.Children.Remove(webBrowser); } if (doc != null) { doc.clear(); } webBrowser = new WebBrowser(); webBrowser.LoadCompleted += completed; gridwebBrowser.Children.Add(webBrowser); Script.HideScriptErrors(webBrowser, true); if (url == "") { webBrowser.NavigateToString(Properties.Resources.New); doc = webBrowser.Document as HTMLDocument; doc.designMode = "On"; Format.doc = doc; return; } else { webBrowser.Navigate(url); } doc = webBrowser.Document as HTMLDocument; Format.doc = doc; }
public void LoadHtml(string content, string base_uri) { view.NavigateToString(content); }
private void ParseLine(string line) { int lineCount = 0; int maxLineCount = GetMaxLineCount(); string tempLine = line; var sbLine = new StringBuilder(); while (lineCount < maxLineCount) { int charactersFitted = MeasureString(tempLine, (int) Width); string leftSide = tempLine.Substring(0, charactersFitted); sbLine.Append(leftSide); tempLine = tempLine.Substring(charactersFitted, tempLine.Length - (charactersFitted)); lineCount++; } TextBlock textBlock = GetTextBlock(); textBlock.TextWrapping = TextWrapping.Wrap; textBlock.Text = sbLine.ToString(); var wb = new WebBrowser {Height = 10*(textBlock.ActualWidth/320)}; wb.NavigateToString(WebBrowserHelper.WrapHtml(line, Application.Current.RootVisual.RenderSize.Width)); _stackPanel.Children.Add(wb); if (tempLine.Length > 0) ParseLine(tempLine); }
/// <summary> /// Generate right page /// </summary> /// <param name="pageNumber"></param> /// <returns>canvas, right canvas to renderBook()</returns> private Canvas generateRightCanvas(int pageNumber) { SolidColorBrush whiteBrush = new SolidColorBrush(); whiteBrush.Color = Colors.White; Canvas canvas = new Canvas(); canvas.Width = 520; canvas.Height = 720; canvas.Background = whiteBrush; canvas.Margin = new Thickness(520, 0, 0, 0); // Amu WebBrowser wbRightPage = new WebBrowser(); // If there is odd number of pages last page in right will be empty (in future it will be filled with next chapter's first page) if (!(parser.pageCount < (pageNumber + 1))) { wbRightPage.NavigateToString(splittedPages[pageNumber]); } wbRightPage.Width = 490; wbRightPage.Height = 700; wbRightPage.Margin = new Thickness(0, 8, 0, 0); wbRightPage.Foreground = new SolidColorBrush(Colors.Magenta); // set the padding area to top and to left wbRightPage.SetValue(Canvas.LeftProperty, 20.00); wbRightPage.SetValue(Canvas.TopProperty, 50.00); canvas.Children.Add(wbRightPage); Rectangle rectangle = new Rectangle(); rectangle.Width = 32; rectangle.Height = 720; rectangle.Fill = this.Resources["RightShadow"] as LinearGradientBrush; rectangle.Margin = new Thickness(0, 0, 0, 0); canvas.Children.Add(rectangle); return canvas; }
/// <summary> /// Generate left page /// </summary> /// <param name="pageNumber"></param> /// <returns>canvas, left canvas to renderBook()</returns> private Canvas generateLeftCanvas(int pageNumber) { SolidColorBrush whiteBrush = new SolidColorBrush(); whiteBrush.Color = Colors.White; Canvas canvas = new Canvas(); canvas.Width = 520; canvas.Height = 720; canvas.Background = whiteBrush; canvas.Margin = new Thickness(0, 0, 0, 0); WebBrowser wbLeftPage = new WebBrowser(); wbLeftPage.NavigateToString(splittedPages[pageNumber]); wbLeftPage.Width = 490; wbLeftPage.Height = 700; wbLeftPage.Margin = new Thickness(8, 8, 0, 0); wbLeftPage.Foreground = new SolidColorBrush(Colors.Magenta); // set the padding area to top and to left wbLeftPage.SetValue(Canvas.LeftProperty, 20.00); wbLeftPage.SetValue(Canvas.TopProperty, 50.00); canvas.Children.Add(wbLeftPage); Rectangle rectangle = new Rectangle(); rectangle.Width = 32; rectangle.Height = 720; rectangle.Fill = this.Resources["LeftShadow"] as LinearGradientBrush; rectangle.Margin = new Thickness(490, 0, 0, 0); canvas.Children.Add(rectangle); return canvas; }
private void DisplayHTML(String html) { reportContent.Children.Clear(); WebBrowser browser = new WebBrowser(); browser.Navigating += new System.Windows.Navigation.NavigatingCancelEventHandler(browser_Navigating); browser.NavigateToString(html); reportContent.Children.Add(browser); }
private void handleCompleted(WebBrowser browser, /*ProgressBar progress,*/ object sender, DownloadStringCompletedEventArgs e, IScrapper scrapper) { if (e.Error != null) { browser.NavigateToString("Error occured: " + e.Error.ToString()); } else { if (e.Cancelled) { browser.NavigateToString("Request was cancelled"); } else { var searchResults = scrapper.Scrape(e.Result); browser.NavigateToString(GetHtml(searchResults)); } } }
private void previewButton_Click(object sender, RoutedEventArgs e) { string rawWikipage = String.Empty; string htmlWikipage = String.Empty; FlowDocument document = this.outputBox.Document; TextRange wholeDocument = new TextRange(document.ContentStart, document.ContentEnd); rawWikipage = wholeDocument.Text; htmlWikipage = engine.Render(rawWikipage); Window browserWindow = new Window(); //Uri iconUri = new Uri("pack://application:,,,./VPN.ico", UriKind.RelativeOrAbsolute); //browserWindow.Icon = BitmapFrame.Create(iconUri); StackPanel panel = new StackPanel(); WebBrowser browser = new WebBrowser(); browser.Height = 800; browser.NavigateToString(htmlWikipage); panel.Children.Add(browser); browserWindow.Content = panel; browserWindow.Show(); }