Mohamed Thaufeeq
Mohamed Thaufeeq

Reputation: 1677

WP - how to remove underline in hyperlinkButton programmatically?

I have developed an hyperlinkButton in C#. The underline in hyperlinkButton irritates me. I don't know how to remove it. Help me to remove the underline and i need answer in C#. [It's an WP8 app]

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

Upvotes: 3

Views: 2746

Answers (2)

Matt
Matt

Reputation: 4602

I don't know another way but setting the ControlTemplate in XAML. But you can use it in 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
};

Hope this helps

Upvotes: 2

gunr2171
gunr2171

Reputation: 17520

To quote Douglas Stockwell

You can set properties directly, or use a style:

<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>

Upvotes: 6

Related Questions