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