C# WPF Text with links

前端 未结 3 455
萌比男神i
萌比男神i 2021-01-02 12:29

I just found myself a new challenge: Make a Word Processor that is in handling more like the web than plain text. Designing a nice framework for this is what i cant wait to

3条回答
  •  一向
    一向 (楼主)
    2021-01-02 13:18

    The simplest way is to handle RequestNavigate event like this:

    
    ...
    myLink.RequestNavigate += HandleRequestNavigate;
    ...
    
    private void HandleRequestNavigate(object sender, RoutedEventArgs e)
    {
       var link = (Hyperlink)sender;
       var uri = link.NavigateUri.ToString();
       Process.Start(uri);
       e.Handled = true;
    }
    
    

    There are some issues with starting a default browser by passing url to the Process.Start and you might want to google for a better way to implement the handler.

提交回复
热议问题