public void ReactTextViewManager_Selection_InlineUIContainer() { // <Span><Run>Sample test text.</Run><Run>Second text.</Run></Span><Run>Third text.</Run><InlineUIContainer><TextBlock Text='InlineUIContainerText'/></InlineUIContainer> Span span = new Span(); Run run = new Run(); run.Text = "Sample test text."; span.Inlines.Add(run); Run run1 = new Run(); run1.Text = "Second text."; span.Inlines.Add(run1); Run run2 = new Run(); run2.Text = "Third text."; InlineUIContainer inlineUIContainer = new InlineUIContainer(); TextBlock tb = new TextBlock(); tb.Text = "InlineUIContainerText"; inlineUIContainer.Child = tb; RichTextBlock rtb = CreateWithInlines(new Inline[] { span, run2, inlineUIContainer }); Paragraph paragraph = rtb.Blocks.First() as Paragraph; TextPointer start = paragraph.ContentStart.GetPositionAtOffset(49, LogicalDirection.Forward); TextPointer end = paragraph.ContentStart.GetPositionAtOffset(50, LogicalDirection.Forward); var text = ReactTextViewManager.GetStringByStartAndEndPointers(rtb, start, end); Assert.AreEqual(text, @"InlineUIContainerText"); }
internal static InlineUIContainer GetAncestorInline(TextPointer position, Type ancestorType) { InlineUIContainer cont = null; Paragraph parent = position.Parent as Paragraph; Inline run = position.Parent as Inline; if (parent != null && parent.Inlines != null) { foreach (Inline inline in parent.Inlines) { if (inline is InlineUIContainer) { cont = inline as InlineUIContainer; //cont = parent.Inlines.FirstInline as InlineUIContainer; } else { cont = GetInlineUICont(inline as Span); } if (null != cont) { break; } } } else if (run != null && run.NextInline != null) { //while(run.NextInline != null) cont = GetInlineFromCollection(run.SiblingInlines); } return(cont); }
public void InsertImage(string fname, string time, byte[] data) { Bold info_run = new Bold(); info_run.Inlines.Add(fname + " [" + time + "]\n"); Paragraph info_p = new Paragraph(); info_p.Inlines.Add(info_run); msgRecRichTextBox.Blocks.Add(info_p); Stream stream = new MemoryStream(data); BitmapImage bImg = new BitmapImage(); bImg.SetSource(stream); Image img = new Image(); img.Source = bImg; img.Height = (img.Width = 200) * 1.2; InlineUIContainer container = new InlineUIContainer(); container.Child = img; TextPointer EndofContent = msgRecRichTextBox.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward); msgRecRichTextBox.Selection.Select(EndofContent, EndofContent); msgRecRichTextBox.Selection.Insert(container); Paragraph blank_p = new Paragraph(); blank_p.Inlines.Add(""); msgRecRichTextBox.Blocks.Add(blank_p); }
private static Inline GenerateIFrame(HtmlNode node) { try { Span s = new Span(); s.Inlines.Add(new LineBreak()); InlineUIContainer iui = new InlineUIContainer(); //WebView ww = new WebView() { Source = new Uri(node.Attributes["src"].Value, UriKind.Absolute) // , Width = Int32.Parse(node.Attributes["width"].Value), Height = Int32.Parse(node.Attributes["height"].Value) }; int height = 160; int width = 300; WebView ww = new WebView() { Source = new Uri(node.Attributes["src"].Value, UriKind.Absolute) , Width = width, Height = height }; iui.Child = ww; s.Inlines.Add(iui); s.Inlines.Add(new LineBreak()); return(s); } catch (Exception ex) { return(null); } }
/// <summary> /// Called when [preview key down]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="KeyEventArgs" /> instance containing the event data.</param> private void OnPreviewKeyDown(object sender, KeyEventArgs e) { InlineUIContainer container = null; if (e.Key == Key.Back) { container = this.CaretPosition.GetAdjacentElement(LogicalDirection.Backward) as InlineUIContainer; } else if (e.Key == Key.Delete) { if (this.Selection.Text == " ") { TextPointer moveTo = this.CaretPosition.GetNextInsertionPosition(LogicalDirection.Backward); this.CaretPosition = moveTo; } if (this.CaretPosition != null) { container = this.CaretPosition.GetAdjacentElement(LogicalDirection.Forward) as InlineUIContainer; } } if (container != null) { var tokenContainer = container.Child as TokenContainer; if (tokenContainer != null) { var token = this.RemoveTokenByKey(tokenContainer.Key); this.SetText(this.Text.Replace(string.Format("{0}{1}", token.Content, token.Delimiter), "")); } } }
private void ClearSelection() { TextRange range = new TextRange(ContentStart, ContentEnd); range.ApplyPropertyValue(TextElement.ForegroundProperty, Foreground); range.ApplyPropertyValue(TextElement.BackgroundProperty, null); _selectedRange = null; foreach (Inline inline in Inlines) { if (inline is InlineUIContainer) { InlineUIContainer container = inline as InlineUIContainer; container.BaselineAlignment = BaselineAlignment.TextBottom; if (container.Child is Grid) { (container.Child as Grid).ClearValue(Grid.BackgroundProperty); (container.Child as Grid).ClearValue(TextElement.ForegroundProperty); } } } ClearContextMenu(); }
public InlineUIContainer GetUIElementUnderSelection(BlockCollection blocks) { foreach(Block block in blocks) { Paragraph ph = block as Paragraph; if(ph != null) { foreach(object obj in ph.Inlines) { if(obj is Run) continue; InlineUIContainer cont = obj as InlineUIContainer; if(cont != null && cont.ContentStart.CompareTo(Selection.Start) > 0 && cont.ContentStart.CompareTo(Selection.End) < 0) { return cont; } } } else { List lst = block as List; if(lst != null) { foreach(ListItem lstItem in lst.ListItems) { InlineUIContainer retVal = GetUIElementUnderSelection(lstItem.Blocks); if(retVal != null) return retVal; } } } } return null; }
private static Inline GenerateHyperLink(HtmlNode node) { Span s = new Span(); InlineUIContainer iui = new InlineUIContainer(); HyperlinkButton hb = new HyperlinkButton() { NavigateUri = new Uri(node.Attributes["href"].Value, UriKind.Absolute), Content = CleanText(node.InnerText) }; if (node.ParentNode != null && (node.ParentNode.Name == "li" || node.ParentNode.Name == "LI")) { hb.Style = (Style)Application.Current.Resources["RTLinkLI"]; } else if ((node.NextSibling == null || string.IsNullOrWhiteSpace(node.NextSibling.InnerText)) && (node.PreviousSibling == null || string.IsNullOrWhiteSpace(node.PreviousSibling.InnerText))) { hb.Style = (Style)Application.Current.Resources["RTLinkOnly"]; } else { hb.Style = (Style)Application.Current.Resources["RTLink"]; } iui.Child = hb; s.Inlines.Add(iui); return(s); }
public static void AddToParagraph(this RichTextBox richTextBox, object itemToAdd, Func <object, InlineUIContainer> createInlineElementFunct) { try { Paragraph paragraph = richTextBox?.GetParagraph(); if (paragraph == null) { return; } InlineUIContainer elementToAdd = createInlineElementFunct(itemToAdd); if (paragraph.Inlines.FirstInline == null) { // First element to insert paragraph.Inlines.Add(elementToAdd); } else { // Insert at the end paragraph.Inlines.InsertAfter(paragraph.Inlines.LastInline, elementToAdd); } richTextBox.CaretPosition = richTextBox.CaretPosition.DocumentEnd; } catch { } }
void RichTextBox_PreviewKeyDown(object sender, KeyEventArgs e) { InlineUIContainer container = null; if (e.Key == Key.Back) { container = _rtb.CaretPosition.GetAdjacentElement(LogicalDirection.Backward) as InlineUIContainer; } else if (e.Key == Key.Delete) { //if the selected text is a blank space, I will assume that a token item is selected. //if a token item is selected, we need to move the caret position to the left of the element so we can grab the InlineUIContainer if (_rtb.Selection.Text == " ") { TextPointer moveTo = _rtb.CaretPosition.GetNextInsertionPosition(LogicalDirection.Backward); _rtb.CaretPosition = moveTo; } //the cursor is to the left of a token item container = _rtb.CaretPosition.GetAdjacentElement(LogicalDirection.Forward) as InlineUIContainer; } //if the container is not null that means we have something to delete if (container != null) { var token = (container as InlineUIContainer).Child as TokenItem; if (token != null) { SetTextInternal(Text.Replace(token.TokenKey, "")); } } }
private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { if (Clipboard.ContainsImage()) { BitmapSource bs = Clipboard.GetImage(); Image image = new Image(); image.Width = bs.Width; image.Height = bs.Height; image.Stretch = Stretch.None; image.Source = bs; InlineUIContainer MyUI = new InlineUIContainer(image, richTxt.Selection.Start); Paragraph myParagraph = new Paragraph(); myParagraph.Inlines.Add(MyUI); //object ortf = Clipboard.GetData(DataFormats.Rtf); //Clipboard.SetData(DataFormats.Rtf, ortf); richTxt.Paste(); } else { richTxt.Paste(); } //object o = Clipboard.GetData(DataFormats.Html); AdjustImg(); }
private Inline CreateCodeInline(HtmlNode node) { if (string.IsNullOrEmpty(node.InnerText)) { return(null); } var span = new Span(); var border = new Border { BorderBrush = new SolidColorBrush(Style.Foreground), Padding = new Thickness(5, 3, 5, 3), BorderThickness = new Thickness(1) }; var textBlock = new TextBlock { FontSize = Style.FontSize / 1.5, Text = WebUtility.HtmlDecode(node.InnerText) }; border.Child = textBlock; var inlineContainer = new InlineUIContainer(); inlineContainer.Child = border; span.Inlines.Add(inlineContainer); return(span); }
private static InlineUIContainer GetInlineUICont(Span parent) { InlineUIContainer cont = null; if (null != parent) { foreach (Inline inline in parent.Inlines) { if (inline is InlineUIContainer) { cont = (InlineUIContainer)inline; return(cont); } else { cont = GetInlineUICont(inline as Span); } if (null != cont) { break; } } } return(cont); }
/// <summary> /// Renders an image element. /// </summary> /// <param name="inlineCollection"> The list to add to. </param> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> private void RenderImage(InlineCollection inlineCollection, ImageInline element, RenderContext context) { var image = new Image(); var imageContainer = new InlineUIContainer() { Child = image }; // if url is not absolute we have to return as local images are not supported if (!element.Url.StartsWith("http") && !element.Url.StartsWith("ms-app")) { RenderTextRun(inlineCollection, new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); return; } image.Source = new BitmapImage(new Uri(element.Url)); image.HorizontalAlignment = HorizontalAlignment.Left; image.VerticalAlignment = VerticalAlignment.Top; image.Stretch = ImageStretch; ToolTipService.SetToolTip(image, element.Tooltip); // Try to add it to the current inlines // Could fail because some containers like Hyperlink cannot have inlined images try { inlineCollection.Add(imageContainer); } catch { // Ignore error } }
private Inline GenerateImage(HtmlNode node) { Span s = new Span(); try { InlineUIContainer iui = new InlineUIContainer(); var sourceUri = System.Net.WebUtility.HtmlDecode(node.Attributes["src"].Value); Image img = new Image() { Source = new BitmapImage(new Uri(sourceUri, UriKind.Absolute)), Stretch = Stretch.Uniform, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; img.ImageOpened += img_ImageOpened; img.ImageFailed += img_ImageFailed; iui.Child = img; s.Inlines.Add(iui); s.Inlines.Add(new LineBreak()); } catch (Exception ex) { Debug.WriteLine("Something went wrong trying to generate the image with source <" + node.Attributes["src"] + ">."); Debug.WriteLine(ex.Message); } return(s); }
private Inline GenerateLI(HtmlNode node) { Span s = new Span(); InlineUIContainer iui = new InlineUIContainer(); TextBlock itemBullet = new TextBlock() { Margin = new Thickness(listNumbers.Count * this.ListIndentation, 0, 5, 0) }; int itemNumber = listNumbers.Pop(); if (node.ParentNode.Name == "ul" || node.ParentNode.Name == "UL") { itemBullet.Text = UlBulletType; } else { itemBullet.Text = itemNumber.ToString() + ")"; } listNumbers.Push(itemNumber + 1); iui.Child = itemBullet; s.Inlines.Add(iui); AddChildren(s.Inlines, node); s.Inlines.Add(new LineBreak()); return(s); }
/// <summary> /// Adds a child at the given index. /// </summary> /// <param name="parent">The parent view.</param> /// <param name="child">The child view.</param> /// <param name="index">The index.</param> public void AddView(DependencyObject parent, DependencyObject child, int index) { var span = (Span)parent; var inlineChild = child as Inline; if (inlineChild == null) { inlineChild = new InlineUIContainer { Child = (UIElement)child, }; } #if WINDOWS_UWP span.Inlines.Insert(index, inlineChild); var parentUIElement = AccessibilityHelper.GetParentElementFromTextElement(span); if (parentUIElement != null) { AccessibilityHelper.OnChildAdded(parentUIElement, child); } #else ((IList)span.Inlines).Insert(index, inlineChild); #endif }
/// <summary> /// 单击单个收件人,设置选中状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EmailReceiverButton_Click(object sender, RoutedEventArgs e) { foreach (var block in this.Document.Blocks) { var paragraph = block as Paragraph; if (paragraph == null) { continue; } foreach (var item in paragraph.Inlines) { InlineUIContainer container = item as InlineUIContainer; if (container == null) { continue; } EmailReceiverButton button = container.Child as EmailReceiverButton; if (sender == button) { button.IsSelected = true; } else { button.IsSelected = false; } } } }
/// <summary> /// Renders a horizontal rule element. /// </summary> /// <param name="element"></param> /// <param name="currentBlocks"></param> private void RenderHorizontalRule(HorizontalRuleBlock element, BlockCollection currentBlocks) { // This is going to be weird. To make this work we need to make a UI element // and fill it with text to make it stretch. If we don't fill it with text I can't // make it stretch the width of the box, so for now this is an "ok" hack. InlineUIContainer contianer = new InlineUIContainer(); Grid grid = new Grid(); grid.Height = 2; grid.Background = new SolidColorBrush(Color.FromArgb(255, 153, 153, 153)); // Add the expanding text block. TextBlock magicExpandingTextBlock = new TextBlock(); magicExpandingTextBlock.Foreground = new SolidColorBrush(Color.FromArgb(255, 153, 153, 153)); magicExpandingTextBlock.Text = "This is Quinn writing magic text. You will never see this. Like a ghost! I love Marilyn Welniak! This needs to be really long! RRRRREEEEEAAAAALLLLYYYYY LLLOOOONNNGGGG. This is Quinn writing magic text. You will never see this. Like a ghost! I love Marilyn Welniak! This needs to be really long! RRRRREEEEEAAAAALLLLYYYYY LLLOOOONNNGGGG"; grid.Children.Add(magicExpandingTextBlock); // Add the grid. contianer.Child = grid; // Make the new horizontal rule paragraph Paragraph horzPara = new Paragraph(); horzPara.Margin = new Thickness(0, 12, 0, 12); horzPara.Inlines.Add(contianer); // Add it currentBlocks.Add(horzPara); }
private static Inline GenerateHyperLink(HtmlNode node) { Span s = new Span(); InlineUIContainer iui = new InlineUIContainer(); Debug.WriteLine(node.Attributes["href"].Value); Hyperlink hb; string lk = node.Attributes["href"].Value; if (!lk.Contains("http")) { lk = string.Format("http://ifixit.com/{0}", lk); } hb = new Hyperlink() { NavigateUri = new Uri(lk, UriKind.RelativeOrAbsolute) }; hb.Inlines.Add(GenerateSpan(node, " ")); //if (node.ParentNode != null && (node.ParentNode.Name == "li" || node.ParentNode.Name == "LI")) // hb.Style = (Style)Application.Current.Resources["RTLinkLI"]; //else if ((node.NextSibling == null || string.IsNullOrWhiteSpace(node.NextSibling.InnerText)) && (node.PreviousSibling == null || string.IsNullOrWhiteSpace(node.PreviousSibling.InnerText))) // hb.Style = (Style)Application.Current.Resources["RTLinkOnly"]; //else // hb.Style = (Style)Application.Current.Resources["RTLink"]; // iui.Child = hb; s.Inlines.Add(hb); return(s); }
/// <summary> /// Insert one line into document /// </summary> /// <param name="p">paragraph</param> /// <param name="phrase">text</param> /// <param name="foreground">foreground color</param> /// <param name="underlined">true if underlined</param> private void InsertPhraseIntoDocument(Paragraph p, string phrase, System.Windows.Media.Brush foreground, bool underlined = false) { foreach (string s in phrase.SplitForTex(this.DelimiterLeft, this.DelimiterRight)) { if (s.StartsWith(this.DelimiterLeft.ToString()) && s.EndsWith(this.DelimiterRight.ToString())) { string tex = s.Substring(1, s.Length - 2); WpfMath.Controls.FormulaControl fc = new WpfMath.Controls.FormulaControl(); fc.Formula = tex; InlineUIContainer i = new InlineUIContainer(fc); if (foreground != null) { i.Foreground = foreground; } p.Inlines.Add(i); } else { Run t = new Run(s); if (foreground != null) { t.Foreground = foreground; } if (underlined) { p.Inlines.Add(new Underline(t)); } else { p.Inlines.Add(t); } } } }
private void _btnInsert_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = "Image files (*.jpg,*.jpeg,*.jpe,*.jfif,*.png)|*.jpg;*.jpeg;*.jpe;*.jfif;*.png"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { string fileName = dlg.FileName; if (File.Exists(fileName)) { BitmapImage bi = new BitmapImage(new Uri(fileName)); Image image = new Image(); image.Source = bi; image.Width = bi.Width; image.Height = bi.Height; image.Stretch = Stretch.Fill; image.Loaded += ImageOnLoaded; InlineUIContainer container = new InlineUIContainer(image); Paragraph paragraph = new Paragraph(container); _richTextBox.Document.Blocks.Add(paragraph); } } } catch { throw; } }
public object Convert(object value, Type targetType, object parameter, string language) { //Create a new RichTextBox. RichTextBlock MyRTB = new RichTextBlock(); // Create a Run of plain text and hyperlink. Run myRun = new Run(); myRun.Text = " are enabled in a read-only RichTextBox."; InlineUIContainer mylinkcont = new InlineUIContainer(); HyperlinkButton MyLink = new HyperlinkButton(); MyLink.Content = "Hyperlink"; MyLink.NavigateUri = new Uri("http://www.msdn.com"); mylinkcont.Child = MyLink; // Create a paragraph and add the Run and hyperlink to it. Paragraph myParagraph = new Paragraph(); myParagraph.Inlines.Add(mylinkcont); myParagraph.Inlines.Add(myRun); // Add the paragraph to the RichTextBox. MyRTB.Blocks.Add(myParagraph); return(MyRTB); }
private void btnImage_Click(object sender, RoutedEventArgs e) { //Uri imageUri = new Uri("http://t3.baidu.com/it/u=2499248362,4035544451&fm=0&gp=0.jpg", UriKind.RelativeOrAbsolute); //InlineUIContainer container = new InlineUIContainer(); //// System.Windows.Documents.TextElement. //container.Child = CreateImageFromUri(imageUri, 200, 150); //rtb.Selection.Insert(container); //ReturnFocus(); InsertURL cw = new InsertURL(rtb.Selection.Text, true); cw.HasCloseButton = false; cw.Closed += (s, args) => { if (cw.DialogResult.Value) { InlineUIContainer container = new InlineUIContainer(); int w = 200; int.TryParse(cw.txtWidth.Text, out w); //图片宽度 int h = 150; int.TryParse(cw.txtHeight.Text, out h); //图片高度 //输入图片路径 if (cw.fs != null) { BitmapImage bmp = null; try { bmp = cw.bmp; Image img = new Image(); img.Stretch = Stretch.Uniform; img.Width = w; img.Height = h; //图片高度 img.Source = bmp; img.Tag = bmp.UriSource.ToString(); // bmp.DownloadProgress += new EventHandler<DownloadProgressEventArgs>(bmp_DownloadProgress); container.Child = img; rtb.Selection.Insert(container); ReturnFocus(); } catch { bmp = null; } } else { string url = cw.txtURL.Text; //添加图片插入到InlineUIContainer之中 Uri imageUri = new Uri(url, UriKind.RelativeOrAbsolute); container.Child = Utility.CreateImageFromUri(imageUri, w, h); rtb.Selection.Insert(container); ReturnFocus(); } } }; cw.Show(); }
private static bool TryGetNotationAndDirection( MathBox mathBox, Key key, out LogicalDirection direction, out NotationBase notation ) { direction = LogicalDirection.Forward; InlineUIContainer forwardElement = mathBox.ForwardUiElement; InlineUIContainer backwardElement = mathBox.BackwardUiElement; InlineUIContainer inlineUiContainer = null; if (key == Key.Right && forwardElement != null) { inlineUiContainer = forwardElement; direction = LogicalDirection.Forward; } else if (key == Key.Left && backwardElement != null) { inlineUiContainer = backwardElement; direction = LogicalDirection.Backward; } if (!(inlineUiContainer?.Child is NotationBase control)) { notation = null; return(false); } notation = control; return(true); }
/// <summary> /// Replaces the strings in the Text property with tokens. /// </summary> private void ReplaceTextWithTokens() { // The "Text" property is not linked to the RichTextBox contents, thus we need to clear the RichTextBox // and add each token individually to the contents. this.Clear(); var tokens = new ObservableKeyedCollection <string, Token>(token => token.Key); if (!string.IsNullOrEmpty(Text)) { Paragraph para = this.CaretPosition.Paragraph ?? new Paragraph(); if (para != null) { string[] text = Text.Split(new[] { this.TokenDelimiter }, StringSplitOptions.RemoveEmptyEntries); foreach (string t in text) { var token = this.GetTokenByItemSource(t); token.Content = this.GetContentByToken(token); InlineUIContainer tokenContainer = this.CreateTokenContainer(token); para.Inlines.Add(tokenContainer); tokens.Add(token); } } if (!this.Document.Blocks.Contains(para)) { this.Document.Blocks.Add(para); } } this.Tokens = tokens; }
/// <summary> /// Traverses only passed paragraph /// </summary> /// <param name="p"></param> public void TraverseParagraph(Paragraph p) { if (p.Inlines != null && p.Inlines.Count > 0) { Inline il = p.Inlines.FirstInline; while (il != null) { Run r = il as Run; if (r != null) { VisualVisited(this, r, true); il = il.NextInline; continue; } InlineUIContainer uc = il as InlineUIContainer; if (uc != null && uc.Child != null) { VisualVisited(this, uc.Child, true); il = il.NextInline; continue; } Figure fg = il as Figure; if (fg != null) { TraverseBlockCollection(fg.Blocks); } il = il.NextInline; } } }
private void SelectAll() { TextRange range = new TextRange(ContentStart, ContentEnd); Brush background = FindBackground(); Brush foreground = FindForeground(); range.ApplyPropertyValue(TextElement.ForegroundProperty, background); range.ApplyPropertyValue(TextElement.BackgroundProperty, foreground); foreach (Inline inline in Inlines) { if (inline is InlineUIContainer) { InlineUIContainer container = inline as InlineUIContainer; container.BaselineAlignment = BaselineAlignment.TextBottom; if (container.Child is Grid) { (container.Child as Grid).Background = foreground; TextElement.SetForeground(container.Child, background); } } } ContextMenu contextMenu = new ContextMenu(); contextMenu.Items.Add(new MenuItem { Header = "Copy", Command = ApplicationCommands.Copy }); ContextMenu = contextMenu; _selectedRange = range; }
private static Inline GenerateImage(HtmlNode node) { Span s = new Span(); try { InlineUIContainer iui = new InlineUIContainer(); var sourceUri = System.Net.WebUtility.HtmlDecode(node.Attributes["src"].Value); Image img = new Image() { Source = new BitmapImage(new Uri(sourceUri, UriKind.Absolute)) }; img.Stretch = Stretch.Uniform; img.VerticalAlignment = VerticalAlignment.Top; img.HorizontalAlignment = HorizontalAlignment.Left; img.Width = Convert.ToDouble(node.Attributes["width"].Value); img.Height = Convert.ToDouble(node.Attributes["height"].Value); //img.ImageOpened += img_ImageOpened; //img.ImageFailed += img_ImageFailed; // img.Tapped += ScrollingBlogPostDetailPage.img_Tapped; iui.Child = img; s.Inlines.Add(iui); s.Inlines.Add(new LineBreak()); } catch (Exception ex) { } return(s); }
/// <summary> /// Appends given line to the given paragraph /// </summary> /// <param name="currentParagraph"></param> /// <param name="line"></param> public void AppendTextToParagraph(Paragraph currentParagraph, string line) { foreach (string token in Regex.Split(line, regexStatementsPattern)) { if (token.StartsWith("Load") || token.StartsWith("Select")) { //match the selected item Match m = Regex.Match(token, @"""(.*)"""); string selectedItem = m.Groups[1].Value; ComboBoxStatement statementBox; if (token.StartsWith("Load")) { statementBox = new ComboBoxStatement(Statement.Load, selectedItem); } else { statementBox = new ComboBoxStatement(Statement.Select, selectedItem); } InlineUIContainer myInlineUIContainer = new InlineUIContainer(statementBox); currentParagraph.Inlines.Add(myInlineUIContainer); } else { currentParagraph.Inlines.Add(new Run(token)); } } }
public DependencyObject[] Generate(HtmlNode node, IHtmlTextBlock textBlock) { try { var link = node.Attributes["href"]; var block = new TextBlock(); block.Foreground = Foreground; var element = new InlineUIContainer(); element.Child = block; var hr = new Underline(); foreach (var child in node.Children) { var leaves = child.GetLeaves(textBlock).ToArray(); if (leaves.Length > 0) { foreach (var item in leaves.OfType<Inline>()) hr.Inlines.Add(item); } else if (!string.IsNullOrEmpty(child.Value)) hr.Inlines.Add(new Run { Text = child.Value }); } block.Inlines.Add(hr); var action = CreateLinkAction(block, link, textBlock); block.Tapped += (sender, e) => { if (!e.Handled) { e.Handled = true; action(); } }; return new DependencyObject[] { element }; } catch { return node.GetLeaves(textBlock); // suppress link } }
public void GetRadDocumentAndValues(out RadDocument document, out string[] values, ObservableCollection<Models.EventsGroup> eventGroups, DateTime startDate, DateTime endDate) { document = new RadDocument { SectionDefaultPageMargin = new Padding(20, 10, 20, 10), LayoutMode = DocumentLayoutMode.Paged, SectionDefaultPageOrientation = PageOrientation.Portrait }; document.Style.SpanProperties.FontSize = 12; document.Style.ParagraphProperties.SpacingBefore = 5; var section = new Section(); document.Sections.Add(section); foreach (var eventGroup in eventGroups) { var paragraphBorder = new Paragraph { SpacingBefore = 10, SpacingAfter = 10 }; var separatorBorder = new System.Windows.Controls.Border { BorderThickness = new Thickness(3) }; var colorBrush = new SolidColorBrush { Color = Colors.SkyBlue }; separatorBorder.BorderBrush = colorBrush; separatorBorder.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; var container = new InlineUIContainer { Height = 3, Width = 745, UiElement = separatorBorder }; paragraphBorder.Inlines.Add(container); section.Blocks.Add(paragraphBorder); //Add Event Date to the Heading var paragraphEventDate = new Paragraph(); var span = new Span(eventGroup.EventDate.ToString("dddd dd/MM/yy")) { FontSize = 14, FontWeight = FontWeights.Bold }; paragraphEventDate.Inlines.Add(span); section.Blocks.Add(paragraphEventDate); foreach (var Event in eventGroup.Events) { var table = new Table(); section.Blocks.Add(table); var row = new TableRow(); table.Rows.Add(row); var cell = new TableCell(); row.Cells.Add(cell); cell.Background = Colors.GhostWhite; cell.Borders = new TableCellBorders(BorderStyle.Single, Colors.Black); var paragraphEventName = new Paragraph(); var spanEventName = new Span((Event.EventType == null ? String.Empty : Event.EventType.Name) + ": " + Event.Name + " (" + (Event.PrimaryContact == null ? String.Empty : Event.PrimaryContact.ContactName) + ") Num of People : " + Event.Places) { FontWeight = FontWeights.Bold }; paragraphEventName.Inlines.Add(spanEventName); cell.Blocks.Add(paragraphEventName); CreateEventGolfsBlock(Event.EventGolfs, cell); CreateEventCateringsBlock(Event.EventCaterings, cell); CreateEventRoomsBlock(Event.EventRooms, cell); CreateEventNotesBlock(Event.EventNotes, cell); section.Blocks.Add(new Paragraph()); } } values = new string[2]; values[0] = "Event Synopsis Report "; values[1] = "Synopsis for events between " + startDate.ToString("d") + " and " + endDate.ToString("d"); }
/// <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 } }