/// <summary>Creates the UI elements for the given HTML node and HTML view.</summary> /// <param name="node">The HTML node.</param> /// <param name="htmlView">The HTML view.</param> /// <returns>The UI elements.</returns> public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView) { var controls = node.GetChildControls(htmlView); foreach (var leave in controls) { var element = leave as TextElement; if (element != null) element.FontWeight = FontWeights.Bold; } return controls; }
/// <summary>Creates the UI elements for the given HTML node and HTML view.</summary> /// <param name="node">The HTML node.</param> /// <param name="htmlView">The HTML view.</param> /// <returns>The UI elements.</returns> public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView) { var controls = node.GetChildControls(htmlView); foreach (var leave in controls) { var element = leave as TextElement; if (element != null) { #if WINRT element.FontStyle = FontStyle.Italic; #else element.FontStyle = FontStyles.Italic; #endif } } return controls; }
/// <summary>Creates the UI elements for the given HTML node and HTML view.</summary> /// <param name="node">The HTML node.</param> /// <param name="textBlock">The HTML view.</param> /// <returns>The UI elements.</returns> public DependencyObject[] CreateControls(HtmlNode node, IHtmlView textBlock) { var leaves = node.GetChildControls(textBlock); if (leaves.Length == 1 && leaves[0] is Panel) leaves = new[] { leaves[0] }; if (leaves.Length > 0) { var element = leaves.First() as FrameworkElement; if (element != null) element.Margin = new Thickness(element.Margin.Left, 0, element.Margin.Right, element.Margin.Bottom); element = leaves.Last() as FrameworkElement; if (element != null) element.Margin = new Thickness(element.Margin.Left, element.Margin.Top, element.Margin.Right, 0); } return leaves; }
/// <summary>Creates the UI elements for the given HTML node and HTML view.</summary> /// <param name="node">The HTML node.</param> /// <param name="htmlView">The HTML view.</param> /// <returns>The UI elements.</returns> public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView) { var list = new List<DependencyObject>(); var isFirst = true; var addTopMargin = true; var current = new List<Inline>(); foreach (var child in node.GetChildControls(htmlView)) { if (isFirst) { if (child is Run) { var run = (Run)child; run.Text = run.Text.TrimStart(' ', '\t'); // TODO: Trim all white spaces } isFirst = false; } if (child is Run && UseTextSplitting && ((Run)child).Text.Contains("\n")) // used to avoid 2048px max control size { // split text var run = (Run) child; var splits = run.Text.Split('\n'); // join some splits to avoid small junks var currentSplit = ""; var newSplits = new List<string>(); for (var i = 0; i < splits.Length; i++) { var split = splits[i]; if (i != 0 && currentSplit.Length + split.Length > 16) { newSplits.Add(currentSplit); currentSplit = split; } else currentSplit += (i != 0 ? "\n" : "") + split; } newSplits.Add(currentSplit); // create multiple text blocks splits = newSplits.ToArray(); for (var i = 0; i < splits.Length; i++) { var split = splits[i]; current.Add(new Run { Text = split }); if (i < splits.Length - 1) // dont create for last CreateTextBox(node, list, current, htmlView, i == 0 && addTopMargin, false); } addTopMargin = list.Count == 0; } else if (child is Inline) current.Add((Inline)child); else { CreateTextBox(node, list, current, htmlView, addTopMargin, true); list.Add(child); addTopMargin = true; } } CreateTextBox(node, list, current, htmlView, addTopMargin, true); if (list.Count == 0) return null; return list.ToArray(); }
/// <summary>Creates the UI elements for the given HTML node and HTML view.</summary> /// <param name="node">The HTML node.</param> /// <param name="htmlView">The HTML view.</param> /// <returns>The UI elements.</returns> public DependencyObject[] CreateControls(HtmlNode node, IHtmlView htmlView) { try { var link = node.Attributes["href"]; var hyperlink = new Hyperlink(); if (Foreground != null) hyperlink.Foreground = Foreground; #if !WINRT hyperlink.MouseOverForeground = htmlView.Foreground; hyperlink.TextDecorations = TextDecorations.Underline; #endif foreach (var child in node.Children) { var leaves = child.GetControls(htmlView).ToArray(); if (leaves.Length > 0) { foreach (var item in leaves) { if (item is Inline) hyperlink.Inlines.Add((Inline) item); else { var container = new InlineUIContainer {Child = (UIElement) item}; hyperlink.Inlines.Add(container); } } } else if (child is HtmlTextNode && !string.IsNullOrEmpty(((HtmlTextNode)child).Text)) hyperlink.Inlines.Add(new Run { Text = ((HtmlTextNode)child).Text }); } #if WINRT var action = CreateLinkAction(hyperlink, link, htmlView); hyperlink.Click += (sender, e) => { action(); ((Control)htmlView).Focus(FocusState.Programmatic); }; #else var action = CreateLinkAction(hyperlink, link, htmlView); hyperlink.Command = new RelayCommand(delegate { if (!PhoneApplication.IsNavigating) action(); }); #endif return new DependencyObject[] { hyperlink }; } catch { return node.GetChildControls(htmlView); // suppress link } }