HOW?? Silverlight menu to EW pages.. RRS feed

  • Question

  • I've been searching around ALOT...
    I've created buttons in Silverlight 3. Rectangles and "empty buttons". Lets say their names are "Home" and "About"... In Expression web 3 I made 2 html pages named "Home" and "About". How can I make the Silverlight HOME-button connect to the EW3 HOME-page and vice versa??

    I'm a neewbie so please explain in baby-language.. ;D
    Friday, November 20, 2009 2:08 PM

All replies

  • I am not sure what sort of Blend project you used.  I will give an example using a Silverlight 3 Applicaiton + Website (we are going to need a website with a web.config file anyway to test this).  And I will do that with the language as Visual Basic.

    In this project, I create a button named btnGoMicrosoft with Content = Go Microsoft.

    I then switch from properties to events where I double click in the click-event box.  That brings up the Visual Basic code editor. First I type Imports System.Windows.Browser above all the code.  I then add

    Dim op As System.Windows.Browser.HtmlPopupWindowOptions = Nothing 'supply properties if desired
    Dim URI As New System.Uri("http://www.microsoft.com")
    HtmlPage.PopupWindow(URI, "_blank", op) '_blank for new window

    to the code for btnGoMicrosoft_Click

    My final page of code looks as below. Run the project and you should see the result you want.

    Imports System.Windows.Browser 'for HtmlPage popup window
    Partial Public Class MainControl
    Inherits UserControl
    Public Sub New()
    End Sub

    Private Sub btnGoMicrosoft_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
    'TODO: Add event handler implementation here.
    Dim op As System.Windows.Browser.HtmlPopupWindowOptions = Nothing 'supply properties if desired
    Dim URI As New System.Uri("http://www.microsoft.com")
    , "_blank", op) 'blank for new window
    End Sub

    End Class

    Saturday, November 21, 2009 7:44 PM
  • it seems a long way round just to navigate to a next page in Flash it would look like this:


     and what would be the code for c#
    Saturday, November 21, 2009 8:41 PM
  • it is not that much really, just three lines of code which could probably be combined into one.  And that is just my way.  someone else may have something easier.

    For C#, try this inside the button click event.

        System.Windows.Browser.HtmlPopupWindowOptions op = null;
        System.Uri URI = new System.Uri("http://www.microsoft.com");
        HtmlPage.PopupWindow(URI, "_blank", op);

    Also you want to put at the top of the code page this line:

    using System.Windows.Browser; 
    Saturday, November 21, 2009 9:39 PM
  • Thanks! I will try that as soon as possible! :D
    Sunday, November 22, 2009 1:44 AM
  • what if i just want to go to a page in my own production i'm not interested in opening a blank page or web site and I can't believe that no one has addressed this!
    Monday, November 23, 2009 8:53 AM
  • This is simpler with no popup window, where Example.htm is in the same folder as the current page.  Otherwise provide a relative path to Example.htm


    New Uri("Example.htm", UriKind.Relative))

    Monday, November 23, 2009 2:47 PM
  • Great answer, thanks. But sorry if I'm being stupid.. but how can this link to my Expression web 3 page? And when the button is pressed, is a new window going to pop up?
    Monday, November 23, 2009 3:39 PM
  • It all depends on where your target web page is. If it is in the same web site as the page with your code, then you use a relative link. 

    HtmlPage.Window.Navigate(New Uri("TheRelative URI", UriKind.Relative))

    If it is in a separate web site, then you use an absolute link.

    HtmlPage.Window.Navigate(New Uri(http://www......", UriKind.Absolute))

    And this code does not open a new window.

    Monday, November 23, 2009 5:10 PM
  • But I can't type in a URI like "http://www.blabla...." because my project isnt on the internet. It's in here: C:\Documents and Settings\ASD\My documents\My Web Sites\Home.html

    haha I'm such a noob.. but don't hate me.
    Monday, November 23, 2009 6:03 PM