Exemplo n.º 1
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var a = (IHtmlAnchorElement)element;

            if (a.ChildElementCount == 0)
            {
                var anchor = new Hyperlink
                {
                    Foreground = new SolidColorBrush(Colors.LightBlue)
                };
                anchor.Click += async (sender, args) =>
                {
                    var dialog = new MessageDialog(a.Href, "使用浏览器打开");
                    dialog.Commands.Add(new UICommand("确定", async cmd =>
                    {
                        var success = await Launcher.LaunchUriAsync(new Uri(a.Href, UriKind.Absolute));
                        if (success)
                        {
                            anchor.Foreground = new SolidColorBrush(Colors.Purple);
                        }
                    }));
                    dialog.Commands.Add(new UICommand("取消"));
                    await dialog.ShowAsync();
                };

                parent.Add(anchor);

                context.RenderNode(element, new SpanContainer(anchor));
            }
            else
            {
                context.RenderNode(element,parent);
            }
        }
Exemplo n.º 2
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var a = (IHtmlAnchorElement)element;

            if (a.ChildElementCount == 0)
            {
                var anchor = new Hyperlink
                {
                    Foreground = new SolidColorBrush(Colors.LightBlue)
                };
                anchor.Click += async(sender, args) =>
                {
                    var dialog = new MessageDialog(a.Href, "使用浏览器打开");
                    dialog.Commands.Add(new UICommand("确定", async cmd =>
                    {
                        var success = await Launcher.LaunchUriAsync(new Uri(a.Href, UriKind.Absolute));
                        if (success)
                        {
                            anchor.Foreground = new SolidColorBrush(Colors.Purple);
                        }
                    }));
                    dialog.Commands.Add(new UICommand("取消"));
                    await dialog.ShowAsync();
                };

                parent.Add(anchor);

                context.RenderNode(element, new SpanContainer(anchor));
            }
            else
            {
                context.RenderNode(element, parent);
            }
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var span = new Span();

            parent.Add(span);
            context.RenderNode(element, new SpanContainer(span));
        }
Exemplo n.º 4
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var span = new Span();

            var color = element.Style("color");

            if (string.IsNullOrEmpty(color) == false)
            {
                color = color.Trim().TrimStart('#');
                if (color.Length == 6)
                {
                    var  sR = color.Substring(0, 2);
                    var  sG = color.Substring(2, 2);
                    var  sB = color.Substring(4, 2);
                    byte r, g, b;
                    if (byte.TryParse(sR, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out r) &&
                        byte.TryParse(sG, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out g) &&
                        byte.TryParse(sB, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b))
                    {
                        var value = Color.FromArgb(255, r, g, b);
                        if (value != Colors.White && value != Colors.Black)
                        {
                            span.Foreground = new SolidColorBrush(value);
                        }
                    }
                }
            }

            parent.Add(span);
            context.RenderNode(element, new SpanContainer(span));
        }
Exemplo n.º 5
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var italic = new Italic();

            parent.Add(italic);
            context.RenderNode(element, new SpanContainer(italic));
        }
Exemplo n.º 6
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var paragraph = new Paragraph();

            parent.Add(paragraph);
            context.RenderNode(element, new OrderListContainer(paragraph));
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var bold = new Bold();

            parent.Add(bold);
            context.RenderNode(element, new SpanContainer(bold));
        }
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var paragraph = new Paragraph()
     {
         TextAlignment = TextAlignment.Center
     };
     parent.Add(paragraph);
     context.RenderNode(element, new ParagraphContainer(paragraph));
 }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var paragraph = new Paragraph()
            {
                TextAlignment = TextAlignment.Center
            };

            parent.Add(paragraph);
            context.RenderNode(element, new ParagraphContainer(paragraph));
        }
Exemplo n.º 10
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var paragraph = new Paragraph
            {
                Margin = new Thickness(0, 10, 0, 10)
            };

            parent.Add(paragraph);
            context.RenderNode(element, new ParagraphContainer(paragraph));
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var audio = (IHtmlAudioElement)element;

            var mediaElement = new MediaElement
            {
                Source = new Uri(audio.Source),
                AreTransportControlsEnabled = true,
                MinHeight = 65
            };

            parent.Add(mediaElement);
            context.RenderNode(element, parent);
        }
Exemplo n.º 12
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var audio = (IHtmlAudioElement)element;

            var mediaElement = new MediaElement
            {
                Source = new Uri(audio.Source),
                AreTransportControlsEnabled = true,
                MinHeight = 65
            };

            parent.Add(mediaElement);
            context.RenderNode(element, parent);
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var border = new Border
            {
                BorderThickness = new Thickness(1),
                BorderBrush = new SolidColorBrush(Colors.Gray),
                Margin = new Thickness(0, 5, 0, 5),
                Padding = new Thickness(10)
            };
            parent.Add(border);

            var richTextBlock = new RichTextBlock();
            border.Child = richTextBlock;
            context.RenderNode(element, new RichTextBlockContainer(richTextBlock));
        }
Exemplo n.º 14
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var border = new Border
            {
                BorderThickness = new Thickness(1),
                BorderBrush     = new SolidColorBrush(Colors.Gray),
                Margin          = new Thickness(0, 5, 0, 5),
                Padding         = new Thickness(10)
            };

            parent.Add(border);

            var richTextBlock = new RichTextBlock();

            border.Child = richTextBlock;
            context.RenderNode(element, new RichTextBlockContainer(richTextBlock));
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var table = (IHtmlTableElement)element;

            var grid = new Grid();

            foreach (var child in table.Rows)
            {
                var row = child as IHtmlTableRowElement;
                if (row != null)
                {
                    grid.RowDefinitions.Add(new RowDefinition());
                    int columnCount = 0;
                    foreach (var column in row.Cells)
                    {
                        var richTextBlock = new RichTextBlock()
                        {
                            IsTextSelectionEnabled = false
                        };
                        var cellRender = new Border()
                        {
                            Child = richTextBlock,
                            Padding = new Thickness(5)
                        };
                        context.RenderNode(column, new RichTextBlockContainer(richTextBlock));
                        Grid.SetColumn(cellRender, columnCount);
                        Grid.SetRow(cellRender, grid.RowDefinitions.Count - 1);
                        grid.Children.Add(cellRender);

                        columnCount++;

                        if (grid.ColumnDefinitions.Count < columnCount)
                        {
                            grid.ColumnDefinitions.Add(new ColumnDefinition());
                        }
                    }
                }
            }

            parent.Add(grid);
        }
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var table = (IHtmlTableElement)element;

            var grid = new Grid();

            foreach (var child in table.Rows)
            {
                var row = child as IHtmlTableRowElement;
                if (row != null)
                {
                    grid.RowDefinitions.Add(new RowDefinition());
                    int columnCount = 0;
                    foreach (var column in row.Cells)
                    {
                        var richTextBlock = new RichTextBlock()
                        {
                            IsTextSelectionEnabled = false
                        };
                        var cellRender = new Border()
                        {
                            Child   = richTextBlock,
                            Padding = new Thickness(5)
                        };
                        context.RenderNode(column, new RichTextBlockContainer(richTextBlock));
                        Grid.SetColumn(cellRender, columnCount);
                        Grid.SetRow(cellRender, grid.RowDefinitions.Count - 1);
                        grid.Children.Add(cellRender);

                        columnCount++;

                        if (grid.ColumnDefinitions.Count < columnCount)
                        {
                            grid.ColumnDefinitions.Add(new ColumnDefinition());
                        }
                    }
                }
            }

            parent.Add(grid);
        }
Exemplo n.º 17
0
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var paragraph = new Paragraph();
     parent.Add(paragraph);
     context.RenderNode(element, new OrderListContainer(paragraph));
 }
Exemplo n.º 18
0
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var span = new Span();
     parent.Add(span);
     context.RenderNode(element, new SpanContainer(span));
 }
Exemplo n.º 19
0
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     context.RenderNode(element, parent);
 }
Exemplo n.º 20
0
        public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
        {
            var parentContainer = (parent as RichTextBlockContainer).Get();

            Span span = new Span();
            Underline underline = null;

            var textDecoration = element.Style("text-decoration");
            if (!string.IsNullOrEmpty(textDecoration))
            {
                if (textDecoration == "underline")
                {
                    underline = new Underline();
                    underline.Inlines.Add(span);
                }
            }

            var color = element.Style("color");
            if (string.IsNullOrEmpty(color) == false)
            {
                color = color.Trim().TrimStart('#');
                if (color.Length == 6)
                {
                    var sR = color.Substring(0, 2);
                    var sG = color.Substring(2, 2);
                    var sB = color.Substring(4, 2);
                    byte r, g, b;
                    if (byte.TryParse(sR, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out r)
                        && byte.TryParse(sG, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out g)
                        && byte.TryParse(sB, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out b))
                    {
                        var value = Color.FromArgb(255, r, g, b);
                        if (value != Colors.White && value != Colors.Black)
                        {
                            if (underline != null)
                            {
                                underline.Foreground = new SolidColorBrush(value);
                            }
                            else
                            {
                                span.Foreground = new SolidColorBrush(value);
                            }
                        }
                    }
                }
            }

            var fontSize = element.Style("font-size");
            if (!string.IsNullOrEmpty(fontSize))
            {
                fontSize = fontSize.Replace("px", "");
                if (underline != null)
                {
                    underline.FontSize = double.Parse(fontSize);
                }
                else
                {
                    span.FontSize = double.Parse(fontSize);
                }
            }

            var fontWeight = element.Style("font-weight");
            if (!string.IsNullOrEmpty(fontWeight))
            {
                if (underline != null)
                {
                    underline.FontWeight = FontWeights.Bold;
                }
                else
                {
                    span.FontWeight = FontWeights.Bold;
                }
            }


            var textAlign = element.Style("text-align");
            if (!string.IsNullOrEmpty(textAlign))
            {
                if (textAlign == "left")
                {
                    parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Left;
                }
                else if (textAlign == "right")
                {
                    parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Right;
                }
                else
                {
                    parentContainer.TextAlignment = Windows.UI.Xaml.TextAlignment.Center;
                }
            }

            var textStyle = element.Style("text-style");
            if (!string.IsNullOrEmpty(textStyle))
            {
                if (textStyle == "italic")
                {
                    if (underline != null)
                    {
                        underline.FontStyle = FontStyle.Italic;
                    }
                    else
                    {
                        span.FontStyle = FontStyle.Italic;
                    }
                }
            }

            if (underline != null)
            {
                parent.Add(underline);
                context.RenderNode(element, new SpanContainer(underline));
            }
            else
            {
                parent.Add(span);
                context.RenderNode(element, new SpanContainer(span));
            }
        }
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var bold = new Bold();
     parent.Add(bold);
     context.RenderNode(element, new SpanContainer(bold));
 }
Exemplo n.º 22
0
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     context.RenderNode(element, parent);
 }
Exemplo n.º 23
0
 public virtual void RenderElement(IElement element, ITextContainer parent, RenderContextBase context)
 {
     var italic = new Italic();
     parent.Add(italic);
     context.RenderNode(element, new SpanContainer(italic));
 }