locked
switching page in silverlight application RRS feed

  • Question

  • hi

    I am creating silverlight application I need to switch from one page to another through the Eventhandlers.

    I created one button in Main page when i click that button it should go to another page

    Can any one help me


    siva ramamoorthy
    • Edited by naveensiva Friday, April 29, 2011 9:34 AM
    Friday, April 29, 2011 5:56 AM

All replies

  • Hello Naveensiva,

    on your UI you need a Frame control. Then you need some Page objects. The Page objects will be displayed inside the Frame control. The logic for the naviagtion between the pages is provided by the Frame control.

    To naviagte between the pages on user click actions, you need some HyperlinkButton controls and then use the Frame.Navigate() method. Therefore, you could for example hook up the Click() event of each HyperlinkButton and then call the Frame.Naviagte() method inside the event handler of the delegate.

     

    ' In the constructor of MainPage.xamk.vb:
    
     AddHandler shb1.Click, AddressOf OnHyperlinkButtonClicked
    
    ' this is the delegate:
     Private Sub OnHyperlinkButtonClicked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    
     contentFrame.Navigate(New Uri("/" + CType(sender, HyperlinkButton).Tag.ToString + ".xaml", UriKind.RelativeOrAbsolute))
    
     End Sub
    
    

    In the snippet above, shb1 is the x:name of a single HyperlinkButton. In Xaml, the name of the targeted page was assigned as value to the Tag property of this HyperlinkButton. This Tag value is catched in the event handler to build the uri to which shall be navigated when the user clicked on the HyperlinkButton.

    Hope this helps as a first step.

    Best regards,

    Martin


    Friday, April 29, 2011 6:52 AM
  • hi Martin

    I am doing in C# and I am in Very beginner stage can you tel the step by step procedure for this

     


    siva ramamoorthy
    Friday, April 29, 2011 9:14 AM
  • Hi

    i have an simple idea you can make a main layout and a Grid (for parent) and then make your different pages as a User Control and then Add the User Control to the Grid.

    it makes you web application faster. because do not require redirecting.

     

     

    MyGrid.Children.Clear();
    MyGrid.Children.Add(new MyUserControl());
    

     

    you can check my website pkd2010.dlinkddns.com but only few times it is running due to the fact i use VPN Connection and send traffic for use it as a Anti-Proxy in IRAN.and my website will be disconnected when i connect to VPN.


    PK DEVELOPER
    Wednesday, May 11, 2011 4:49 PM
  • I recommend you to create a Silverlight Navigation Application. So the project will create the needed code pices.

    Thursday, May 12, 2011 5:11 AM