1

我是 silverlight 的新手,从我收集的信息来看,没有任何关于分页的直接功能,所以我从这里下载了 helix 项目。我发现它相当有用,但未能找到一种方法(使用 helix)通过 code-behind 导航页面。我需要这个的原因是,如果方法成功执行,我想导航到另一个页面。

4

1 回答 1

2

在 RootPage.xaml.cs 的 OnLoaded 事件中可以看到如下代码:

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

当通过调用 RootPage.xaml 中定义的 Frame 控件实例的 Navigate 方法加载 RootPage 时,这会以编程方式导航到 Page1.xaml(实现 NavigationPage):

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

该 Navigate 方法依次调用 Frame 的封装 StackJournal 实例的 Navigate 方法。

如果您处于无法直接访问父框架的页面(即除 RootPage 之外的任何页面)的代码隐藏中,例如 Page1.xaml,您需要引发一个 RequestNavigate 事件,该事件将冒泡到最近的父框架.

以下代码显示如何以编程方式从单击 Page1.xaml 的按钮直接导航到 Page3.xaml:

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

请注意,targetName 是“rootFrame”,即最终执行导航的父 Frame 对象。

于 2009-02-12T22:48:39.080 回答