Wednesday, December 1, 2010

WPF Hyperlink default style

Tried to find the default style of a Hyperlink and discovered that neither Google, nor Expression Blend or ShowMeTheTemplate have it. So I had to disassemble WPF assembly with .NET Reflector+BAML viewer. Here is the style for Aero NormalColor theme, just for reference purposes:
   <Style x:Key="{x:Type Hyperlink}" TargetType="{x:Type Hyperlink}">
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Foreground" Value="Red" />
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground"
                       Value="{DynamicResource {x:Static GrayTextBrush}}" />
            <Trigger Property="IsEnabled" Value="true">
                <Setter Property="Cursor" Value="Hand" />
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="TextDecorations" Value="Underline" />
Oh, a slight surprise for me was that the hyperlink colors are not bound to any SystemColor members. No, they are just Red and Blue nailed in the style. Why?....


  1. I was looking for the system color for a hyperlink, so this post is very interesting! Thanks for the info.

  2. Why? must be the most common thing that enters my head while doing WPF/XAML.
    This is a very helpful find.

    Thanks a lot.

  3. This was really helpful in making a LinkLabel for WPF - instead of embedding a Run of text in a Hyperlink inside a TextBox (to get the Hyperlink behavior), I could just set this style (named LinkLabel) and apply it to a TextBox and it looks the same. This helped me avoid the visited behavior (I wanted the link to always look active, not visited), and simplified the XAML. Thanks!

  4. Thank you very much. It is very useful for me.