WPF hyperlink

First, add the style

<Style x:Key="LinkLabelStyle">   
<Setter Property="Control.Padding" Value="0" />
<Setter Property="Control.VerticalAlignment" Value="Center" />
</Style>
二、Xaml标记
<Label Canvas.Left="29"  Canvas.Top="320" x:Name="productLink" x:Uid="productLink" Style="{StaticResource LinkLabelStyle}" >    
<Label.Content>
<Hyperlink x:Name="hyperlink" x:Uid="hyperlink" NavigateUri="http://www.mtdzsp.com" Style="{StaticResource LinkLabelStyle}" Hyperlink.RequestNavigate="hyperlink_RequestNavigate"> = "More"TextThe TextBlock
< Foreground="Black"/>
</Hyperlink>
</Label.Content>
</Label>


Third, the code

     private void hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
        {
            if (e.Uri != null && string.IsNullOrEmpty(e.Uri.OriginalString) == false)
            {
                string uri = e.Uri.AbsoluteUri;
                Process.Start(new ProcessStartInfo(uri));
                e.Handled = true;
              
            }
        }

 

Reproduced in: https: //www.cnblogs.com/OnlyVersion/p/4018344.html

Guess you like

Origin blog.csdn.net/weixin_34279061/article/details/93293219