tags:

views:

288

answers:

2

When I run this and click on the link, I would expect a browser to open and it go to google, but nothing happens:

<Window x:Class="TestHyperlink2343.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <TextBlock>
            You and read this or 
            <Hyperlink NavigateUri="http://www.google.com"&gt;go to google</Hyperlink>
             etc.
        </TextBlock>
    </Grid>
</Window>

So then I replace the above code with the following and still nothing happens. However, surprisingly, if I right click on the link, it goes to google:

<Window x:Class="TestHyperlink2343.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <TextBlock>
            You and read this or 
            <Hyperlink MouseDown="Hyperlink_MouseDown">go to google</Hyperlink>
             etc.
        </TextBlock>
    </Grid>
</Window>

private void Hyperlink_MouseDown(object sender, MouseButtonEventArgs e)
{
    System.Diagnostics.Process.Start("http://www.google.com");
}

Why don't these examples work as expected and how can I get a simple hyperlink to work as users are accustomed to them working in web browsers (left click, open browser, go to site)?

Addendum

I solved this by creating my own hyperlink without the Hyperlink element like this:

<TextBlock Text="More info at wikipedia" 
  TextDecorations="Underline" 
  MouseDown="TextBlock_MouseDown_Wikipedia"/>

private void TextBlock_MouseDown_Wikipedia(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    System.Diagnostics.Process.Start("http://www.wikipedia.com");
}

Strange that hyperlink doesn't work this easily.

+2  A: 

The MSDN states:

Hyperlink navigation can only occur, however, if either the direct or indirect parent of a Hyperlink is a navigation host, including NavigationWindow, Frame, or any browser that can host XBAPs (which includes Internet Explorer 7, Microsoft Internet Explorer 6, and Firefox 2.0+). For more information, see the Navigation Hosts topic in Navigation Overview.

Without seeing more of your code I don't know whether this applies in your case or not.

ChrisF
A: 

Hm... I get an error :( It says that "Process" does not exist in the namespace System.Diagnostics... Dammit!

Maria