Open WPF form when clicking WPF hyperlink

Hey I want to open a new WPF form when I click in a WPF hyperlink. How can I do that. Ive seen a lot of examples that only opens web url, but I want to open a new WPF form.


You can achive this like this:

<Label Height="25" Margin="26,27,116,0" Name="label1" VerticalAlignment="Top">
    <Hyperlink Click="Hyperlink_Click">Click Me</Hyperlink>

and handle it like this:

private void Hyperlink_Click(object sender, RoutedEventArgs e)
    Window2 form2 = new Window2();

You could just handle the click event:

<Hyperlink Click="Hyperlink_Click">Link</Hyperlink>
private void Hyperlink_Click(object sender, RoutedEventArgs e)
    Dialogue diag = new Dialogue();

You could also go crazy with XAML:

        <Style TargetType="{x:Type Hyperlink}">
                <EventTrigger RoutedEvent="Hyperlink.Click">
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
                                    <local:Dialogue />
                                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
        <Run Text="Open Dialogue"/>

This however is very problematic since once the dialogue is closed it cannot be reopened, that means when you click the hypelink again an exception will be thrown.

Using interactivity you could do this without such problems (needs a reference to the Blend SDK though):

        <i:EventTrigger EventName="Click">
            <t:CreateDialogAction Type="{x:Type local:Dialogue}"/>
        <Run Text="Open Dialogue"/>

The action for this:

public class CreateDialogAction : TriggerAction<Hyperlink>
    public Type Type { get; set; }

    protected override void Invoke(object parameter)
        if (Type != null && Type.IsSubclassOf(typeof(Window)) && Type.GetConstructor(Type.EmptyTypes) != null)
            Window window = Type.GetConstructor(Type.EmptyTypes).Invoke(null) as Window;


<TextBlock Height="23" HorizontalAlignment="Left" Margin="254,130,0,0" Name="textBlock1" VerticalAlignment="Top">
        <Hyperlink Click="Hyperlink_Click">Clique Aqui</Hyperlink>

CodeBehind :

private void Hyperlink_Click(object sender, RoutedEventArgs e)
            MainWindow m = new MainWindow();


And using MVVM you can do in your View

<Hyperlink NavigateUri="{Binding MyUri}" 
           Command="{Binding OpenHyperlinkCommand}">Link text

and in your ViewModel

private ICommand _openHyperlinkCommand;
public ICommand OpenHyperlinkCommand {
        if (_openHyperlinkCommand == null) 
            _openHyperlinkCommand = new RelayCommand<object>(p => ExecuteHyperlink());
        return _openHyperlinkCommand;

private void ExecuteHyperlink() {
    //do stuff here

Need Your Help

Django Tag model design

python django tags scalability

I am wondering if the following is the correct way to create tagging system for images and being able to render a tag cloud: