コード例 #1
0
        private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox text_block = d as RichTextBox;

            if (text_block == null)
            {
                return;
            }
            bool   disableHyperlinks = BrowserNavigationService.GetDisableHyperlinks((DependencyObject)text_block);
            string textId            = BrowserNavigationService.GetTextId((DependencyObject)text_block);

            text_block.Blocks.Clear();
            Paragraph par = new Paragraph();
            string    s   = (string)e.NewValue;

            if (string.IsNullOrEmpty(s))
            {
                return;
            }
            foreach (string str1 in BrowserNavigationService.ParseText(BrowserNavigationService.PreprocessTextForGroupBoardMentions(s)))
            {
                char[] chArray = new char[1] {
                    '\b'
                };
                string[] strArray = str1.Split(chArray);
                if (strArray.Length == 1)
                {
                    BrowserNavigationService.AddRawText(text_block, par, strArray[0]);
                }
                else if (strArray.Length > 1)
                {
                    if (disableHyperlinks)
                    {
                        BrowserNavigationService.AddRawText(text_block, par, strArray[1]);
                    }
                    else
                    {
                        if (strArray[0].Contains(BrowserNavigationService._searchFeedPrefix))
                        {
                            int    num  = strArray[0].IndexOf(BrowserNavigationService._searchFeedPrefix) + BrowserNavigationService._searchFeedPrefix.Length;
                            string str2 = strArray[0].Substring(num);
                            strArray[0] = strArray[0].Substring(0, num) + WebUtility.UrlEncode(str2);
                        }
                        Hyperlink hyperlink = HyperlinkHelper.GenerateHyperlink(strArray[1], strArray[0], (Action <Hyperlink, string>)((h, navstr) =>
                        {
                            EventAggregator.Current.Publish((object)new HyperlinkClickedEvent()
                            {
                                HyperlinkOwnerId = textId
                            });
                            BrowserNavigationService.NavigateOnHyperlink(navstr);
                        }), text_block.Foreground);
                        par.Inlines.Add((Inline)hyperlink);
                    }
                }
            }
            text_block.Blocks.Add((Block)par);
        }
コード例 #2
0
        private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBox text_block = d as RichTextBox;

            if (text_block == null)
            {
                return;
            }
            bool   disableHyperlinks    = BrowserNavigationService.GetDisableHyperlinks((DependencyObject)text_block);
            string textId               = BrowserNavigationService.GetTextId((DependencyObject)text_block);
            bool   hyperlinksForeground = BrowserNavigationService.GetHideHyperlinksForeground((DependencyObject)text_block);

            ((PresentationFrameworkCollection <Block>)text_block.Blocks).Clear();
            Paragraph par = new Paragraph();
            // ISSUE: explicit reference operation
            string newValue = (string)e.NewValue;

            if (string.IsNullOrEmpty(newValue))
            {
                return;
            }
            foreach (string str1 in BrowserNavigationService.ParseText(BrowserNavigationService.PreprocessTextForGroupBoardMentions(newValue)))
            {
                string[] innerSplit = str1.Split('\b');
                if (innerSplit.Length == 1)
                {
                    BrowserNavigationService.AddRawText(text_block, par, innerSplit[0]);
                }
                else if (innerSplit.Length > 1)
                {
                    if (disableHyperlinks)
                    {
                        BrowserNavigationService.AddRawText(text_block, par, innerSplit[1]);
                    }
                    else
                    {
                        if (innerSplit[0].Contains(BrowserNavigationService._searchFeedPrefix))
                        {
                            int    num  = innerSplit[0].IndexOf(BrowserNavigationService._searchFeedPrefix) + BrowserNavigationService._searchFeedPrefix.Length;
                            string str2 = innerSplit[0].Substring(num);
                            innerSplit[0] = innerSplit[0].Substring(0, num) + WebUtility.UrlEncode(str2);
                        }
                        Hyperlink hyperlink = HyperlinkHelper.GenerateHyperlink(innerSplit[1], innerSplit[0], (Action <Hyperlink, string>)((h, navstr) =>
                        {
                            EventAggregator.Current.Publish(new HyperlinkClickedEvent()
                            {
                                HyperlinkOwnerId = textId
                            });
                            if (!string.IsNullOrEmpty(textId))
                            {
                                string str = navstr;
                                if (innerSplit.Length > 2)
                                {
                                    str = str.Replace("https://", "vkontakte://");
                                }
                                EventAggregator.Current.Publish(new PostInteractionEvent()
                                {
                                    PostId = textId,
                                    Action = PostInteractionAction.link_click,
                                    Link   = str
                                });
                            }
                            BrowserNavigationService.NavigateOnHyperlink(navstr);
                        }), ((Control)text_block).Foreground, hyperlinksForeground ? HyperlinkState.MatchForeground : HyperlinkState.Normal);
                        ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)hyperlink);
                    }
                }
            }
            ((PresentationFrameworkCollection <Block>)text_block.Blocks).Add((Block)par);
        }