Silverlight 螺旋代码隐藏页面导航

发布于 2024-07-13 18:28:38 字数 260 浏览 2 评论 0原文

我是 silverlight 的新手,据我所知,没有任何关于分页的直接功能,因此我从 此处 。 我发现它相当有用,但未能找到一种方法(使用螺旋)通过代码隐藏来导航页面。 我需要这个的原因是,如果方法执行成功,我想导航到另一个页面。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再浓的妆也掩不了殇 2024-07-20 18:28:38

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

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

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

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

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

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

以下代码演示如何以编程方式从 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 对象。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文