programmatically make textblock with hyperlink in between text

前端 未结 1 2003
无人共我
无人共我 2020-12-11 15:36

In XAML I have the following code:

    
相关标签:
1条回答
  • 2020-12-11 16:11

    Here's the code to add a TextBlock with a clickable link in the middle :

    Run run1 = new Run("click ");
    Run run2 = new Run(" Please");
    Run run3 = new Run("here.");
    
    Hyperlink hyperlink = new Hyperlink(run3)
                           {
                               NavigateUri = new Uri("http://stackoverflow.com")
                           };
    hyperlink.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(hyperlink_RequestNavigate); //to be implemented
    textBlock1.Inlines.Clear();
    textBlock1.Inlines.Add(run1);
    textBlock1.Inlines.Add(hyperlink);
    textBlock1.Inlines.Add(run2);
    
    0 讨论(0)
提交回复
热议问题