views:

1193

answers:

1

I am new to silverlight and from what I gathered there isnt any direct functionality as regards to paging so I downloaded the helix project from here . I found it rather usefull but failed to find a way(using helix) to navigate the pages through code-behind . The reason why I need this is that I want to navigate to another page if a method executed successfully.

+2  A: 

In the OnLoaded event of RootPage.xaml.cs you can see the following code:

this.rootFrame.Navigate( new Uri( "Page1.xaml", UriKind.Relative ) );

This programatically navigates to Page1.xaml (which implements NavigationPage) when the RootPage loads by calling the Navigate method of an instance of the Frame control defined in RootPage.xaml:

<h:Frame x:Name="rootFrame" Grid.Row="0" Grid.Column="1"
         NavigationUIVisibility="Visible" Margin="4" />

This Navigate method in turn calls the Navigate method of the Frame's encapsulated StackJournal instance.

If you are in the code-behind of a page that does not have access to the parent Frame directly (i.e. any page other than RootPage) such as Page1.xaml you need to raise a RequestNavigate event that will bubble up to the nearest parent Frame.

The following code shows how to navigate programatically from a button click on Page1.xaml directly to Page3.xaml:

private void TestButton_Click(object sender, RoutedEventArgs e)
{
    this.RaiseEvent(NavigationLink.RequestNavigateEvent,
        new RequestNavigateEventArgs(new Uri("Page3.xaml", UriKind.Relative),
        "rootFrame"));
}

Notice the targetName is "rootFrame", the parent Frame object that eventually performs the navigation.

Peter McGrattan
Worked flawlessly, Thanks.
Drahcir