WP - 如何以编程方式删除hyperlinkBut​​ton中的下划线?

时间:2013-08-23 13:24:32

标签: c# windows-phone-8

我在C#中开发了一个hyperlinkBut​​ton。超链接中的下划线让我感到恼火。我不知道如何删除它。帮我删除下划线,我需要在C#中回答。 [它是一个WP8应用程序]

    HyperlinkButton hyperlinkButton = new HyperlinkButton()
    {
        Content = "Click me",
        HorizontalAlignment = HorizontalAlignment.Left,
        NavigateUri = new Uri("http://my-link-com", UriKind.Absolute)
    };

2 个答案:

答案 0 :(得分:6)

引用Douglas Stockwell

您可以直接设置属性,也可以使用样式:

<Style TargetType="{x:Type Hyperlink}">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Foreground" Value="DarkSlateBlue" />
        </Trigger>
    </Style.Triggers>
    <Setter Property="Foreground" Value="SteelBlue" />
    <Setter Property="TextBlock.TextDecorations" Value="{x:Null}" />
</Style>

答案 1 :(得分:2)

我不知道另一种方法,但在XAML中设置ControlTemplate。但是你可以在C#中使用它:

var str =   "<ControlTemplate TargetType=\"HyperlinkButton\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">" +
            "   <TextBlock HorizontalAlignment=\"{TemplateBinding HorizontalContentAlignment}\" Text=\"{TemplateBinding Content}\" VerticalAlignment=\"{TemplateBinding VerticalContentAlignment}\"/>" +
            "</ControlTemplate>";

var template = (ControlTemplate)XamlReader.Load(str);  

HyperlinkButton hyperlinkButton = new HyperlinkButton()
{
    Content = "Click me",
    HorizontalAlignment = HorizontalAlignment.Left,
    NavigateUri = new Uri("http://my-link-com", UriKind.Absolute),
    Template = template
};

希望这有帮助

相关问题