Wpf Hyperlink超链接控件使用

一.在Windows窗口中使用

1.点击链接使用系统默认游览器打开

<TextBlock Margin="10,20,-10,-20">
    默认:
    <Hyperlink NavigateUri="http://www.tianma3798.cn" Click="Hyperlink_Click"
            >www.tianma3798.cnHyperlink>
TextBlock>
private void Hyperlink_Click(object sender, RoutedEventArgs e)
{
    Hyperlink link = sender as Hyperlink;
    Process.Start(new ProcessStartInfo(link.NavigateUri.AbsoluteUri));
}

2.配置默认HyperLink链接样式

定义样式资源


<Style x:Key="hyberlinkEffect" TargetType="{x:Type Hyperlink}">
    <Setter Property="Foreground" Value="#3d6490">Setter>
    <Setter Property="TextBlock.TextDecorations" Value="{x:Null}">Setter>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Foreground" Value="Green">Setter>
            
            <Setter Property="TextBlock.TextDecorations">
                <Setter.Value>
                    <TextDecorationCollection>
                        <TextDecoration Location="Underline"/>
                    TextDecorationCollection>
                Setter.Value>
            Setter>
        Trigger>
    Style.Triggers>
Style>

使用资源

<TextBlock Margin="10,56,-10,-56" >
    使用样式资源:
    <Hyperlink NavigateUri="http://www.tianma3798.cn" ToolTip="欢迎访问,爱短句网"
                Style="{StaticResource hyberlinkEffect}"
            >www.tianma3798.cnHyperlink>
TextBlock>

显示结果:

Wpf Hyperlink超链接控件使用_第1张图片

二、在Page或Iframe中使用

<TextBlock>
    <Hyperlink NavigateUri="http://www.baidu.com"   
            >百度首页Hyperlink>
TextBlock>

Wpf Hyperlink超链接控件使用_第2张图片Wpf Hyperlink超链接控件使用_第3张图片

你可能感兴趣的:(Wpf Hyperlink超链接控件使用)