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}">
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="true">
                <Setter Property="Foreground" Value="Red" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground"
                       Value="{DynamicResource {x:Static GrayTextBrush}}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="true">
                <Setter Property="Cursor" Value="Hand" />
            </Trigger>
        </Style.Triggers>
        <Setter Property="Foreground" Value="Blue" />
        <Setter Property="TextDecorations" Value="Underline" />
    </Style>
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?....

6 comments:

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

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

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

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

    ReplyDelete
  5. Do you live in a high value house, perhaps have a holiday home too or maybe you have high value contents, such as some fine art or expensive jewellery? Perhaps your house or The Celeb Net Worth are simply not 'standard'. If so, you'll need to know how to buy high net worth home insurance.

    ReplyDelete