Printer Friendly Version      Send     
Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight
Controls
 HyperlinkButton Styles and Template...
Silverlight 2
HyperlinkButton Styles and Templates
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This topic describes the styles and templates for the HyperlinkButton control. For more information, see Styling and Templating Overview.

The following table lists the states for the HyperlinkButton control.

State Name

VisualStateGroup Name

Description

Normal

CommonStates

The default state.

MouseOver

CommonStates

The mouse pointer is positioned over the control.

Pressed

CommonStates

The control is pressed.

Disabled

CommonStates

The control is disabled.

Focused

FocusStates

The control has focus.

Unfocused

FocusStates

The control does not have focus.

The following example shows how to add a custom style as a StaticResource. For more information, see Styling and Templating Overview. In this example, the StaticResource refers to an x:Key attribute value that you must add to the Style element when you modify it for your project.

XAML
<HyperlinkButton x:Name="hyperlinkButton1"
    Style="{StaticResource newHyperlinkButtonStyle}" />

The following example shows the default styles and templates for the HyperlinkButton control. To customize these styles, add the following XAML to your project, add an x:Key attribute to the Style element, and then reference the style as shown in the previous example.

XAML
<Style TargetType="HyperlinkButton" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
    <Setter Property="IsEnabled" Value="true" />
    <Setter Property="IsTabStop" Value="true" />
    <Setter Property="Foreground" Value="#FF417DA5" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="TextAlignment" Value="Left" />
    <Setter Property="HorizontalContentAlignment" Value="Left" />
    <Setter Property="VerticalContentAlignment" Value="Top" />
    <Setter Property="TextWrapping" Value="NoWrap" />
    <!-- Cannot currently parse TextDecorationCollection type in XAML so it's being set in code -->
    <!-- <Setter Property="TextDecorations" Value="Underline" /> -->
    <!-- Cannot currently parse FontFamily type in XAML so it's being set in code -->
    <!-- <Setter Property="FontFamily" Value="Trebuchet MS" /> -->
    <Setter Property="FontSize" Value="11" />
    <!-- Cannot currently parse FontWeight type in XAML so it's being set in code -->
    <!-- <Setter Property="FontWeight" Value="Bold" /> -->
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="HyperlinkButton">
                <Grid Cursor="{TemplateBinding Cursor}">
                    <Grid.Resources>
                        <!-- Visual constants used by the template -->
                        <Color x:Key="FocusColor">#FF333333</Color>
                        <SolidColorBrush x:Name="HoverColor" Color="#FF99C3F7"/>
                    </Grid.Resources>
                    <vsm:VisualStateManager.VisualStateGroups>
                        <vsm:VisualStateGroup x:Name="CommonStates">
                            <vsm:VisualState x:Name="Normal" />
                        </vsm:VisualStateGroup>
                        <vsm:VisualStateGroup x:Name="FocusStates">
                            <vsm:VisualState x:Name="Focused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Visible</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </vsm:VisualState>
                            <vsm:VisualState x:Name="Unfocused">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Visibility" Duration="0">
                                        <DiscreteObjectKeyFrame KeyTime="0">
                                            <DiscreteObjectKeyFrame.Value>
                                                <Visibility>Collapsed</Visibility>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </vsm:VisualState>
                        </vsm:VisualStateGroup>
                    </vsm:VisualStateManager.VisualStateGroups>

                    <!-- Focus indicator -->
                    <Rectangle x:Name="FocusVisual" StrokeDashCap="Round" StrokeDashArray=".2 5" Visibility="Collapsed" IsHitTestVisible="false">
                        <Rectangle.Stroke>
                            <SolidColorBrush Color="{StaticResource FocusColor}" />
                        </Rectangle.Stroke>
                    </Rectangle>
                    <!-- HyperlinkButton content -->
                    <ContentPresenter
                      x:Name="Content"
                      Background="{TemplateBinding Background}"
                      Content="{TemplateBinding Content}"
                      ContentTemplate="{TemplateBinding ContentTemplate}"
                      HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                      Padding="{TemplateBinding Padding}"
                      TextAlignment="{TemplateBinding TextAlignment}"
                      TextDecorations="{TemplateBinding TextDecorations}"
                      TextWrapping="{TemplateBinding TextWrapping}"
                      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
                      Margin="0,-2,0,0" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker