示例#1
0
        void SetBio()
        {
            try
            {
                if (BiographyText == null)
                {
                    return;
                }
                BiographyText?.Blocks?.Clear();

                if (User == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(User.Biography))
                {
                    return;
                }


                //using (var pg = new PassageHelper())
                //{
                //    var passages = pg.GetParagraph(User.Biography, CaptionHyperLinkClick);
                //    BiographyText.Blocks.Clear();
                //    BiographyText.Blocks.Add(passages);
                //}
                //using (var pg = new WordsHelper())
                //{
                //    var passages = pg.GetParagraph(User.Biography, CaptionHyperLinkClick);
                //    BiographyText.Blocks.Clear();
                //    passages.ForEach(p =>
                //      BiographyText.Blocks.Add(p));
                //}
                using (var pg = new PassageHelperX())
                {
                    var passages = pg.GetInlines(User.Biography, HyperLinkHelper.HyperLinkClick);
                    BiographyText.Blocks.Clear();
                    BiographyText.FlowDirection = passages.Item2 ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
                    var p = new Paragraph();
                    passages.Item1.ForEach(item =>
                                           p.Inlines.Add(item));
                    BiographyText.Blocks.Add(p);
                }
            }
            catch { }
        }
示例#2
0
 private void TextBlockDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
 {
     try
     {
         if (sender is TextBlock textBlock && textBlock.DataContext is string str && !string.IsNullOrEmpty(str))
         {
             using (var pg = new PassageHelperX())
             {
                 var passages = pg.GetInlines(str, HyperLinkHelper.HyperLinkClick);
                 textBlock.Inlines.Clear();
                 textBlock.FlowDirection = passages.Item2 ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;
                 passages.Item1.ForEach(item =>
                                        textBlock.Inlines.Add(item));
             }
         }
     }
     catch { }
 }
示例#3
0
        private void TextBlockDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            try
            {
                if (sender is TextBlock textBlock && args.NewValue is RecentActivityFeed recentActivity && recentActivity != null)
                {
                    if (recentActivity.StoryType == InstagramApiSharp.Enums.InstaActivityFeedStoryType.LikedTagged)
                    {
                        using (var pg = new PassageHelperX())
                        {
                            var passages = pg.GetInlines(recentActivity.RichText, HyperLinkHelper.HyperLinkClick);
                            textBlock.Inlines.Clear();
                            passages.Item1.ForEach(item =>
                                                   textBlock.Inlines.Add(item));
                        }
                    }
                    else
                    {
                        var textStr = recentActivity.Text;
                        var text    = recentActivity.Text;

                        if (recentActivity.Links?.Count > 0)
                        {
                            foreach (var link in recentActivity.Links)
                            {
                                try
                                {
                                    var mention = textStr.Substring(link.Start, (link.End - link.Start) - 1);
                                    //if (link.Type == InstagramApiSharp.Enums.InstaLinkType.User)
                                    //    text = text.Replace(mention, $"@{mention}");//⥽⍬⥶⍬⥽
                                    //else
                                    text = text.Replace(mention, $"https:\\{mention}".Replace(" ", "⥽⍬⥶⍬⥽"));    //⥽⍬⥶⍬⥽
                                }
                                catch { }
                            }
                        }

                        using (var pg = new PassageHelperX())
                        {
                            var passages = pg.GetInlines(text, HyperLinkHelper.HyperLinkClick);
                            textBlock.Inlines.Clear();
                            passages.Item1.ForEach(item =>
                                                   textBlock.Inlines.Add(item));
                        }
                    }

                    textBlock.Inlines.Add(new LineBreak());
                    var date = "";
                    try
                    {
                        date = (string)DateConverter.Convert(recentActivity.TimeStamp, typeof(DateTime), null, null);
                    }
                    catch { date = ""; }
                    if (!string.IsNullOrEmpty(date))
                    {
                        textBlock.Inlines.Add(new Run
                        {
                            Foreground = (SolidColorBrush)Application.Current.Resources["DefaultInnerForegroundColor"],
                            Text       = date,
                        });
                    }
                }
            }
            catch { }
        }