Navigating AWAY from your Silverlight page

11 03 2010

Sooner or later you’ll want to send people away from your Silverlight site. Maybe to a friends page or a company’s main site? These are two ways of handling navigation easily.

glimmervoid_basin Silverlight

Popup Window

To allow people to continue browsing your site whilst opening links of interest, you might want to open new links in separate windows, or in most cases, separate tabs (new windows are so 2004).

In your codebehind, create a quick HtmlPopupWindowOptions object. This object is reusable if you don’t mind using the same settings for all your new windows. In this example, I’m using a twitter button to open a popup version of my twitter stream. Since twitter works in low resolutions, I can adapt my settings to suit the situation.

private void TwitterButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
HtmlPopupWindowOptions options = new HtmlPopupWindowOptions();
options.Left = 0;
options.Top = 0;
options.Width = 800;
options.Height = 600;

HtmlPage.PopupWindow(new Uri("http://www.twitter.com/viktorlarsson", UriKind.Absolute), "new" , options);
}

Twitter Silverlight

Direct Link

Sometimes a direct approach is better. And hey, if Mr. Smith is more interested in reading somehing Janko wrote than my rundown of my top three shirts to pack, maybe it’s just as well he’s leaving my site.

Old-fashioned navigation is easier to implement than pop-ups. All you need is this line of code:

private void Fake_Janko_Link_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//Muahahahahaha
HtmlPage.Window.Navigate(new Uri("http://www.fragiledevelopment.wordpress.com"));
}

This is also useable if you want to enable e-mail usage on your site. Simply replace the http-link with a mailto link instead. You can even enter a standard subject.

private void LuckButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
HtmlPage.Window.Navigate(new Uri("mailto:Michael.Bjorn@avanade.com?subject=Good Luck in Vegas!"));
}

Feel free to try this out below and wish Michael all the luck he can get

Dice Vegas SilverlightClick me hard!

Advertisements

Actions

Information

6 responses

15 03 2010
Links (3/14/2010) « Steve Pietrek-Everything SharePoint/Silverlight

[…] Navigating AWAY from your Silverlight page […]

20 04 2010
Liboh

Hello!
I’m trying to get the “Direct Link” option explained here, using Silverlight and a button with its ‘Click’ event, but the browser always opens a new window (which is awful).
How can I get the same behavior as your example?

private void FeedbackButton_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Navigate(new Uri(“mailto:any@one.com”));
}

I’m using a Silverlight Navigation Application.
Thanks!

20 04 2010
Viktor Larsson

Hello Liboh!
I think the reason you’re experiencing a popup is because you’re using a “mailto:” link. When you click a mailto link, the default mail program is launched. In my case, this is Microsoft Outlook which always opens a new window. Since the mail program “chooses” how to react to being called, this is beyond your control.

Good luck with your coding!

15 08 2010
Jon Q Public

This page gets a lot of hits, and perhaps for the reason below. Here is code that works in Silverlight 3 to prevent navigation away from a page, such as save changes, saving changes in Silverlight.

protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
if (myBool == true)
{
if (MessageBox.Show(“Click OK to stay on this page, otherwise click Cancel”, “Warning: Stay or Go?”, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{

e.Cancel = true; //will cancel the navigation away from this Silverlight page
}
}
}

20 03 2012
http://andcarinsurancequotes.com

But a smiling visitant here to share the love (:, btw outstanding design and style.

3 06 2013
http://goo.gl/w4mTJ

Good day! Do you know if they make any plugins to assist with Search Engine Optimization?

I’m trying to get my blog to rank for some targeted keywords but I’m not seeing
very good gains. If you know of any please share. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: