Skip to content

Instantly share code, notes, and snippets.

@jeffwilcox
Created December 8, 2010 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffwilcox/733001 to your computer and use it in GitHub Desktop.
Save jeffwilcox/733001 to your computer and use it in GitHub Desktop.
A sample hyperlink button for Windows Phone where the negative margins allow for a larger touch target.
<Style
x:Key="AccentHyperlink"
TargetType="HyperlinkButton">
<Setter Property="Foreground" Value="{StaticResource PhoneAccentBrush}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}" />
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}" />
<Setter Property="Padding" Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="HyperlinkButton">
<Grid
Margin="-4"
IsHitTestVisible="True"
Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup
x:Name="CommonStates">
<VisualState
x:Name="Normal" />
<VisualState
x:Name="MouseOver" />
<VisualState
x:Name="Pressed">
<Storyboard>
<DoubleAnimation
Duration="0"
Storyboard.TargetName="TextElement"
Storyboard.TargetProperty="Opacity"
To="0.5" />
</Storyboard>
</VisualState>
<VisualState
x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames
Storyboard.TargetName="TextElement"
Storyboard.TargetProperty="Foreground">
<DiscreteObjectKeyFrame
KeyTime="0"
Value="{StaticResource PhoneDisabledBrush}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid
Margin="4">
<Grid
Margin="{StaticResource PhoneHorizontalMargin}">
<Grid
Margin="{TemplateBinding Padding}">
<TextBlock
x:Name="TextElement"
Text="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
</Grid>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment