C# Silverlight 3 - 以编程方式在页面之间导航?

发布于 2024-08-06 20:48:53 字数 133 浏览 1 评论 0原文

假设我有一个包含多个页面的 C# Silverlight 3 应用程序。第一页称为主页,第二页称为详细信息。导航到详细信息的唯一方法是以编程方式。我该怎么办?到处寻找答案,我发现的只是 xaml uri 映射器实现....

非常感谢帮助

Say I have a C# Silverlight 3 application with a number of pages. The first page is called Home, and the second page is called Details. The only way to navigate to details is programmatically. How do I do this?! Looked everywhere for the answer and all i've found are xaml uri mapper implementations....

Help greatly appreciated

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

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

发布评论

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

评论(5

别低头,皇冠会掉 2024-08-13 20:48:53

您尝试过导航服务吗?

this.NavigationService.Navigate(new Uri("Details.xaml", UriKind.Relative));

Have you tried the NavigationService?

this.NavigationService.Navigate(new Uri("Details.xaml", UriKind.Relative));

撑一把青伞 2024-08-13 20:48:53

c#:

this.navContent.Navigate(new Uri("Welcome", UriKind.Relative));

XAML:

<navigation:Frame
    x:Name="navContent"
    HorizontalContentAlignment="Stretch"
    VerticalContentAlignment="Stretch"
    Source="Welcome">
    <navigation:Frame.UriMapper>
        <uriMapper:UriMapper>
            <uriMapper:UriMapping Uri="Welcome" MappedUri="/Views/Welcome.xaml" />
            <uriMapper:UriMapping Uri="Profile" MappedUri="/Views/Profile.xaml" />
            <uriMapper:UriMapping Uri="Details/{id}" MappedUri="/Views/Details.xaml?photoid={id}" />
        </uriMapper:UriMapper>
    </navigation:Frame.UriMapper>
</navigation:Frame>

即使你的“详细信息”页面也应该被映射(不管你说什么。)

c#:

this.navContent.Navigate(new Uri("Welcome", UriKind.Relative));

XAML:

<navigation:Frame
    x:Name="navContent"
    HorizontalContentAlignment="Stretch"
    VerticalContentAlignment="Stretch"
    Source="Welcome">
    <navigation:Frame.UriMapper>
        <uriMapper:UriMapper>
            <uriMapper:UriMapping Uri="Welcome" MappedUri="/Views/Welcome.xaml" />
            <uriMapper:UriMapping Uri="Profile" MappedUri="/Views/Profile.xaml" />
            <uriMapper:UriMapping Uri="Details/{id}" MappedUri="/Views/Details.xaml?photoid={id}" />
        </uriMapper:UriMapper>
    </navigation:Frame.UriMapper>
</navigation:Frame>

Even your "details" page should be mapped (despite what you said.)

醉南桥 2024-08-13 20:48:53

C#
App.Current.Host.NavigationState = "/欢迎";

XAML

C#
App.Current.Host.NavigationState = "/Welcome";

XAML

苍白女子 2024-08-13 20:48:53

最好的解决方案是:

将此代码添加到您的 App.xaml.cs 中:

private static Grid root;

private void Application_Startup(object sender, StartupEventArgs e)
{
    root = new Grid();
    root.Children.Add(new MainPage());

    this.RootVisual = root;
}

public static void Navigate(UserControl newPage)
{
    UserControl oldPage = root.Children[0] as UserControl;

    root.Children.Add(newPage);
    root.Children.Remove(oldPage);
}

然后,要在页面之间导航,您只需调用:

App.Navigate(new OtherSamplePage());

The best solution is:

Add this code to your App.xaml.cs:

private static Grid root;

private void Application_Startup(object sender, StartupEventArgs e)
{
    root = new Grid();
    root.Children.Add(new MainPage());

    this.RootVisual = root;
}

public static void Navigate(UserControl newPage)
{
    UserControl oldPage = root.Children[0] as UserControl;

    root.Children.Add(newPage);
    root.Children.Remove(oldPage);
}

And then, to navigate between pages, you'll just have to call:

App.Navigate(new OtherSamplePage());
橘味果▽酱 2024-08-13 20:48:53

尝试使用这个。这对我有用。

((System.Windows.Controls.Frame)(this.Parent)).Navigate(new Uri("/Import",UriKind.Relative));

Try using this. This worked for me.

((System.Windows.Controls.Frame)(this.Parent)).Navigate(new Uri("/Import",UriKind.Relative));

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