How to make a simple hyperlink in XAML?
hyperlink, wpf, xaml
Solution
You can use a Button with a custom control template, the code below is a limited hyperlink style button (for example it only support textual hyperlinks) but maybe it'll point you in the right direction.
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="Link" TargetType="Button">
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<TextBlock TextDecorations="Underline"
Text="{TemplateBinding Content}"
Background="{TemplateBinding Background}"/>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Button Content="Click Me!" Style="{StaticResource Link}"/>
</Page>
Problem
All I want to do is make a little hyperlink in XAML. I've tried everything. I give up. What is the syntax for this? ``` <StackPanel Width="70" HorizontalAlignment="Center"> <Hyperlink Click="buttonClose_Click" Cursor="Hand" Foreground="#555" Width="31" Margin="0 0 0 15" HorizontalAlignment="Right">Close</Hyperlink> <Button Width="60" Margin="0 0 0 3">Test 1</Button> <Button Width="60" Margin="0 0 0 3">Test 2</Button> <Button Width="60" Margin="0 0 0 3">Test 3</Button> <Button Width="60" Margin="0 0 0 3">Test 4</Button> </StackPanel> ``` Visual Studio Team: In Visual Studio 2010 I want Clippy to pop up and say "It seems you are trying to make a hyperlink" and tell me how to do it. Can't you do that with MEF? It would be retro cool, and these little "how do I do what I already know how to do in HTML" issues burn up so much time during the learning process with XAML.