tags:

views:

27

answers:

2

In SL4, I am finding it oddly difficult to figure out how to make a HyperlinkButton navigate to another Silverlight page in the same application when clicked. The structure is:

<HyperlinkButton Content="Technical Information Screen" Height="23"
Name="hyperlinkButton1" Width="320" NavigateUri="/tis.xaml" />

"tis.xaml" is in the same folder as MainPage.xaml, which is where this button is located. When clicked, the button raises "404 Not Found".

If I change to having the NavigateUri get filled programmatically in the MainPage constructor, as in:

hyperlinkButton1.NavigateUri = new Uri("/tis.xaml", UriKind.Relative);

I get the same result, as I do with not decorating with "/", and with UriKind set to Absolute or RelativeOrAbsolute. It is all very mysterious, but I know it must be do-able somehow, or why have the control at all?

A: 

Most likely the issue is with the uri format, try pointing to the aspx page hosting the silverlight control.

hyperlinkButton1.NavigateUri = new Uri("http://foo.page.aspx");

jeffo
+1  A: 

Hyperlink button's default behavior is to point the browser to a different page (i.e. a whole other HTML page).

Navigation between XAML pages within the same application is explained in detail here (I suppose you will have to call NavigationService.Navigate() in the click event of the hyperlink button).

Francesco De Vittori
I tried to follow the examples at the page you link to, but have gotten some bizarre results (including having two pages display simultaneously in the same browser window). NavigationService.Navigate() doesn't even compile successfully.
Cyberherbalist
The easiest is this: in Visual Studio 2010, create a new project. Choose "Silverlight Navigation Application". This will create a couple of pages with everything in place: look at MainPage, there is a Frame and a UriMapper. Hyperlinks will work without any callback/code behind. Starting from there you can easily understand the mechanism and transpose it to your project. I hope this is helpful.
Francesco De Vittori