WP - how to remove underline in hyperlinkButton programmatically?

前端 未结 2 1427
迷失自我
迷失自我 2020-12-21 08:17

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

相关标签:
2条回答
  • 2020-12-21 08:36

    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

    0 讨论(0)
  • 2020-12-21 08:45

    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>
    
    0 讨论(0)
提交回复
热议问题