silverlight2008. 9. 1. 19:47


 

A close friend is learning Silverlight 2 and asked me a pretty mundane question but the problem with those kinds of questions is to designers some namespaces are not right there, and easy to use (not intuitive). The question was how do I make the page go to a url in silverlight. The answer to that is the following:

System.Windows.Browser.HtmlPage.Window.Navigate(...);

The Navigate method is not very easy to get to for those not familiar with all the namespaces, furthermore navigate is overloaded which means you can call it in three different flavors, they are:

1. System.Windows.Browser.HtmlPage.Window.Navigate( Uri ) which takes a uri and makes it go to a specific url inside the browser windows. An example would be:

System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("http://www.coreysportfolio.com"));

2. System.Windows.Browser.HtmlPage.Window.Navigate( Uri, target) which takes a uri and a string for target... like "_blank". An example would be:

System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("http://www.coreysportfolio.com"), "_blank");

3. System.Windows.Browser.HtmlPage.Window.Navigate(uri, target, targetFeatures) which takes a uri, a string for target and finally a string for target features. Target features is like the url in javascript urls for controlling the toolbar, window size and other things. An example would be:

System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("http://www.coreysportfolio.com"), "_blank", "toolbar=0");

Hope that helps. Check out the other methods inside HtmlPage and Window in intellisence, there are all kinds of hidden gems there.

Posted by 동동(이재동)

댓글을 달아 주세요