C# Silverlight 3 - Programmatically Navigate Between Pages?

后端 未结 5 1311
余生分开走
余生分开走 2021-01-02 11:28

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 i

相关标签:
5条回答
  • 2021-01-02 11:43

    Have you tried the NavigationService?

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

    0 讨论(0)
  • 2021-01-02 11:46

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

    XAML

    0 讨论(0)
  • 2021-01-02 11:50

    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());
    
    0 讨论(0)
  • 2021-01-02 11:51

    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.)

    0 讨论(0)
  • 2021-01-02 11:57

    Try using this. This worked for me.

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

    0 讨论(0)
提交回复
热议问题