private void MicroContent_RuleTapped(RuleBlock sender, RuleTappedArgs args)
 {
     RuleTapped?.Invoke(this, args);
 }
Example #2
0
        public void RefreshRule()
        {
            var viewer = GetTemplateChild("Viewer") as RichTextBlock;

            if (viewer == null)
            {
                return;
            }
            viewer.Blocks.Clear();
            if (string.IsNullOrWhiteSpace(Content))
            {
                return;
            }
            var items     = LinkRule.Render(Content, Rules, true);
            var paragraph = new Paragraph();

            foreach (var item in items)
            {
                if (item.Type == BlockType.LINE)
                {
                    paragraph.Inlines.Add(new LineBreak());
                    continue;
                }
                if (item.Type == BlockType.TEXT)
                {
                    var run = new Run
                    {
                        Text     = item.Content,
                        FontSize = FontSize,
                    };
                    paragraph.Inlines.Add(run);
                    continue;
                }
                if (item.Type == BlockType.LINK || item.Type == BlockType.USER)
                {
                    var link = new Hyperlink()
                    {
                        // NavigateUri = new Uri(item.Value as string),
                    };
                    link.Click += (Hyperlink sender, HyperlinkClickEventArgs e) =>
                    {
                        RuleTapped?.Invoke(this, new RuleTappedArgs(item));
                    };
                    link.Inlines.Add(new Run()
                    {
                        Text     = item.Content,
                        FontSize = FontSize,
                    });
                    paragraph.Inlines.Add(link);
                    continue;
                }
                if (item.Type == BlockType.IMAGE)
                {
                    var container = new InlineUIContainer();
                    var img       = new Image
                    {
                        Source = ConverterHelper.ToImg(item.Value as string)
                    };
                    img.Width       = 1.5 * FontSize;
                    container.Child = img;
                    paragraph.Inlines.Add(container);
                }
            }
            viewer.TextWrapping = TextWrapping.Wrap;
            viewer.LineHeight   = 2 * FontSize;
            viewer.Blocks.Add(paragraph);
        }