当前位置: 首页>>代码示例>>C#>>正文


C# Hyperlink.SetBinding方法代码示例

本文整理汇总了C#中System.Windows.Documents.Hyperlink.SetBinding方法的典型用法代码示例。如果您正苦于以下问题:C# Hyperlink.SetBinding方法的具体用法?C# Hyperlink.SetBinding怎么用?C# Hyperlink.SetBinding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.Hyperlink的用法示例。


在下文中一共展示了Hyperlink.SetBinding方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Convert

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            DirectMessage directMessage = value as DirectMessage;
            if (directMessage != null)
            {
                TextBlock tb = new TextBlock();
                TweetsTemplate tweetTemplate = new TweetsTemplate();
                Hyperlink hyperLinkUser = new Hyperlink();
                Style usernameStyle = (Style)tweetTemplate.FindResource("UsernameLinkStyle");
                hyperLinkUser.Style = usernameStyle;
                hyperLinkUser.Command = TOBCommands.ShowUserProfile;
                hyperLinkUser.CommandParameter = directMessage;
                Binding bind = new Binding();
                bind.Source = directMessage;
                hyperLinkUser.SetBinding(Hyperlink.DataContextProperty, bind);
                TextBlock tbUserName = new TextBlock();
                tbUserName.Text = directMessage.UserProfile.ScreenName;
                hyperLinkUser.Inlines.Add(tbUserName);
                tb.Inlines.Add(hyperLinkUser);
                tb.Inlines.Add(new Run(" "));

                string dmContent = directMessage.Text;
                string[] statusParts = dmContent.Split(' ');
                Style linkStyle = (Style)tweetTemplate.FindResource("LinkStyle");
                foreach (String part in statusParts)
                {
                    Run magicRun = new Run();
                    if (part.StartsWith("http"))
                    {
                        Hyperlink link = new Hyperlink();
                        link.Style = linkStyle;
                        link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate);
                        TextBlock tblink = new TextBlock();
                        tblink.Text = part + " ";
                        link.NavigateUri = new Uri(part);
                        link.Inlines.Add(tblink);
                        tb.Inlines.Add(link);
                        magicRun = new Run();
                    }
                    else
                    {
                        magicRun.Text = part + " ";
                        tb.Inlines.Add(magicRun);
                    }
                }

                return tb.Inlines;
            }
            else
            {
                return null;
            }
        }
开发者ID:ankitb,项目名称:TweetOBox,代码行数:53,代码来源:DirectMessageUrlConverter.cs

示例2: PrepareTweetDocument

 private static void PrepareTweetDocument(TextBlock textBlock, MetroTwitStatusBase tweet, bool Notification = false)
 {
     if (DesignerProperties.GetIsInDesignMode((DependencyObject) textBlock))
     return;
       try
       {
     if (textBlock != null && textBlock.Inlines != null && textBlock.Inlines.Count > 0)
       textBlock.Inlines.Clear();
       }
       catch
       {
     foreach (Inline inline in Enumerable.ToArray<Inline>((IEnumerable<Inline>) textBlock.Inlines))
       textBlock.Inlines.Remove(inline);
       }
       if (Notification)
       {
     Span span1 = new Span();
     span1.FontWeight = FontWeights.SemiBold;
     Span span2 = span1;
     Hyperlink hyperlink = new Hyperlink((Inline) new Run("@" + tweet.User.ScreenName));
     hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object)"ModernTextLighterBrush");
     hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("UserProfileCommand")
     {
       Mode = BindingMode.OneWay
     });
     hyperlink.SetBinding(Hyperlink.CommandParameterProperty, (BindingBase) new Binding("CurrentTweet.User.ScreenName")
     {
       Mode = BindingMode.OneWay
     });
     ((TextElementCollection<Inline>) span2.Inlines).Add((Inline) hyperlink);
     ((TextElementCollection<Inline>) span2.Inlines).Add((Inline) new Run()
     {
       Text = ": "
     });
     ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) span2);
       }
       if (tweet != null && tweet.Entities != null && tweet.Entities.Count > 0)
       {
     try
     {
       int[] numArray = StringInfo.ParseCombiningCharacters(tweet.RawText);
       IOrderedEnumerable<Entity> orderedEnumerable = Enumerable.OrderBy<Entity, int>((IEnumerable<Entity>) tweet.Entities, (Func<Entity, int>) (x => x.StartIndex));
       int num1 = 0;
       foreach (Entity entity in (IEnumerable<Entity>) orderedEnumerable)
       {
     int num2 = 0;
     if (numArray.Length < tweet.RawText.Length && entity.StartIndex < numArray.Length)
       num2 = numArray[entity.StartIndex] - entity.StartIndex;
     int num3 = entity.StartIndex + num2;
     int num4 = entity.EndIndex + num2;
     int startIndex1 = num1;
     if (num3 > startIndex1 && startIndex1 < numArray.Length && startIndex1 + (num3 - startIndex1) < numArray.Length)
     {
       string input = WebUtility.HtmlDecode(tweet.RawText.Substring(startIndex1, num3 - startIndex1));
       if (!string.IsNullOrEmpty(input))
       {
         Run run = new Run(Regex.Replace(input, "\n{2,}|(\r\n){2,}", "\n\n"));
         ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) run);
       }
     }
     if (entity is MentionEntity)
     {
       MentionEntity mentionEntity = entity as MentionEntity;
       if (!string.IsNullOrEmpty(mentionEntity.ScreenName))
       {
         Hyperlink hyperlink = new Hyperlink((Inline) new TagMentionLinkRun("@" + mentionEntity.ScreenName))
         {
           CommandParameter = (object) ("@" + mentionEntity.ScreenName)
         };
         hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object) "HyperlinkUsername");
         hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("UserProfileCommand")
         {
           Mode = BindingMode.OneTime
         });
         ((TextElementCollection<Inline>) textBlock.Inlines).Add((Inline) hyperlink);
         hyperlink.ContextMenu = new ContextMenu();
         MenuItem menuItem1 = new MenuItem();
         menuItem1.Header = (object) "Filter tweets from this user";
         menuItem1.CommandParameter = hyperlink.CommandParameter;
         MenuItem menuItem2 = menuItem1;
         menuItem2.SetBinding(MenuItem.CommandProperty, (BindingBase) new Binding("FilterCommand")
         {
           Mode = BindingMode.OneTime
         });
         hyperlink.ContextMenu.Items.Add((object) menuItem2);
       }
     }
     else if (entity is HashTagEntity)
     {
       HashTagEntity hashTagEntity = entity as HashTagEntity;
       if (!string.IsNullOrEmpty(hashTagEntity.Text))
       {
         Hyperlink hyperlink = new Hyperlink((Inline) new TagMentionLinkRun("#" + hashTagEntity.Text))
         {
           CommandParameter = (object) ("#" + hashTagEntity.Text)
         };
         hyperlink.SetResourceReference(TextElement.ForegroundProperty, (object) "HyperlinkHashtag");
         hyperlink.SetBinding(Hyperlink.CommandProperty, (BindingBase) new Binding("TagsCommand")
         {
           Mode = BindingMode.OneTime
//.........这里部分代码省略.........
开发者ID:unbearab1e,项目名称:FlattyTweet,代码行数:101,代码来源:TweetRenderer.cs

示例3: GetInlineCollections

        private InlineCollection GetInlineCollections(TextBlock tb, string statusContent, Binding bind, TweetsTemplate tweetTemplate, Hyperlink hyperLinkUser)
        {
            string[] statusParts = statusContent.Split(' ');
            Style linkStyle = (Style)tweetTemplate.FindResource("LinkStyle");
            string parsedStr = "";
            foreach (String part in statusParts)
            {
                parsedStr = part.TrimStart(_delimChars);

                //Check for links
                if (parsedStr.StartsWith("http") && parsedStr.Length > 7)
                {
                    Hyperlink link = new Hyperlink();
                    link.Style = linkStyle;
                    Run run = new Run(part + " ");

                    try
                    {
                        link.NavigateUri = new Uri(parsedStr.TrimEnd(_delimChars));
                        link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate);
                    }
                    catch (Exception e)
                    {
                        TOB.Logger.TOBLogger.WriteDebugInfo(parsedStr + " failed - " + e.ToString());
                    }

                    link.Inlines.Add(run);
                    tb.Inlines.Add(link);
                }
                //Check for user tags
                else if (parsedStr.StartsWith("@"))
                {
                    Hyperlink hplink = new Hyperlink();
                    hplink.Style = linkStyle;
                    hplink.Command = TOBCommands.ShowUserProfileForTags;
                    hplink.CommandParameter = parsedStr.TrimEnd(_delimChars);
                    hyperLinkUser.SetBinding(Hyperlink.DataContextProperty, bind);
                    Run run = new Run(part + " ");
                    hplink.Inlines.Add(run);
                    tb.Inlines.Add(hplink);

                }
                //check for #tags.
                else if (parsedStr.StartsWith("#"))
                {
                    Hyperlink hplinks = new Hyperlink();
                    hplinks.Style = linkStyle;
                    hplinks.Command = TOBCommands.ShowFilterForTags;
                    hplinks.CommandParameter = parsedStr.TrimEnd(_delimChars);
                    Run run = new Run(part + " ");
                    hplinks.Inlines.Add(run);
                    tb.Inlines.Add(hplinks);
                }
                else
                {
                    Run magicRun = new Run();
                    magicRun.Text = part + " ";
                    tb.Inlines.Add(magicRun);
                }

            }
            return tb.Inlines;
        }
开发者ID:ankitb,项目名称:TweetOBox,代码行数:63,代码来源:TagsLinkConverter.cs

示例4: TwitterStatusText

 private string TwitterStatusText(object value, TextBlock tb, TextBlock tbUserName, string statusContent, Binding bind, Hyperlink hyperLinkUser)
 {
     TwitterStatus twitterStatus = value as TwitterStatus;
     hyperLinkUser.CommandParameter = twitterStatus;
     bind.Source = twitterStatus;
     hyperLinkUser.SetBinding(Hyperlink.DataContextProperty, bind);
     tbUserName.Text = twitterStatus.User.ScreenName;
     hyperLinkUser.Inlines.Add(tbUserName);
     tb.Inlines.Add(hyperLinkUser);
     tb.Inlines.Add(new Run(" "));
     statusContent = twitterStatus.Text;
     return statusContent;
 }
开发者ID:ankitb,项目名称:TweetOBox,代码行数:13,代码来源:TagsLinkConverter.cs

示例5: CreateHyperlink

 public Hyperlink CreateHyperlink(string text, string url, DependencyProperty foreground, FontWeight weight, RoutedEventHandler handler)
 {
     Hyperlink link = new Hyperlink ();
     link.SetBinding (Hyperlink.ForegroundProperty, CreateBinding (this, foreground.Name, BindingMode.OneWay));
     link.Inlines.Add (text);
     link.Tag = url;
     link.Click += handler;
     link.FontWeight = weight;
     return link;
 }
开发者ID:atrandom,项目名称:ktwt,代码行数:10,代码来源:TwitterStatusViewer.xaml.cs

示例6: SetEnabledBinding

 protected override void SetEnabledBinding(Hyperlink instance)
 {
     instance.SetBinding(ContentElement.IsEnabledProperty, GetOneWayBinding(RootDialogModel.BackModel, "Enabled"));
 }
开发者ID:jardrake03,项目名称:incert,代码行数:4,代码来源:BackButtonHyperlinkModel.cs

示例7: SetCommandBinding

 protected override void SetCommandBinding(Hyperlink instance)
 {
     instance.SetBinding(Hyperlink.CommandProperty, GetOneWayBinding(RootDialogModel.BackModel, "Command"));
 }
开发者ID:jardrake03,项目名称:incert,代码行数:4,代码来源:BackButtonHyperlinkModel.cs


注:本文中的System.Windows.Documents.Hyperlink.SetBinding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。