none
change rootvisual mainpage

    Question

  • Hi, I have a MainPage and a Login. In startup application if variable client is nothing I make rootvisual = new(login) else rootvisual = new(MainPage).


    My question is, when I am in a page aspx inside the frame of MainPage I have a comprobation in all inside pages and I want then change again the rootvisual for goes to the login page. How can I do this? I try to call rootvisual inside the page "app.rootvisual...." but not do anything. any idea?


    thanks,

    Saturday, June 04, 2011 1:50 AM

Answers

  • Hi,

    According to your description ,if you use the Navigation Framework and want to navigate to a login page, for my experience you can use NavigationService.Navigate Method to navigate asynchronously to content that is specified by a uniform resource identifier (URI) like this:

    NavigationService.Navigate(new Uri("/OtherViewPage.xaml", UriKind.Relative));

    In addition ,I would recommend that you can check the link below for an article which describes all about the concept of Navigation Framework.

    http://www.codeproject.com/Articles/180658/Navigation-Framework-in-Silverlight-4.aspx

    If you want to navigate to a web page via silverlight application, you can use the code as below:

    System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("http://www.microsoft.com",UriKind.Absolute));

    when I am in a page aspx inside the frame of MainPage I have a comprobation in all inside pages and I want then change again the rootvisual for goes to the login page. How can I do this?

    Base on my understanding ,I would like to suggest you to create a function which is used to navigate the page in App.xaml.cs file as below:

    Grid rootvisual = new Grid();
            public void GotoPage(UserControl nextPage)
            {
                App app = (App)Application.Current;
                app.rootvisual.Children.Clear();
                app.rootvisual.Children.Add(nextPage);
            }
    
            private void Application_Startup(object sender, StartupEventArgs e)
            {
                this.RootVisual = rootvisual;
                rootvisual.Children.Add(new MainPage()); 
            }

    Then ,you can call this function to navigate page as you want like this:

    Code in silverlight page(.xaml.cs file):

    App app = (App)Application.Current; app.GotoPage(new PageClassName()); 

    Hope it can help you.

    Monday, June 13, 2011 4:37 AM

All replies

  • I'd set an instance of the Root frame at app startup because that's when it's easiest to find it.  Stick it around in some static class.  When you want to have the login page take over the rootvisual, refer to that static variable and set its content to a new instance of login.

    Saturday, June 04, 2011 2:35 AM
  • Can you give an example please for I undestand it better. Thanks,

    Saturday, June 04, 2011 2:43 AM
  • I think I misunderstood your question. When I need to have a page take over, this seems to work fine:

    App.Current.RootVisual = new Page();

    Not sure why that's not working for you.

    Saturday, June 04, 2011 3:11 AM
  • App.Current.RootVisual = new Page();, this not works,

    Saturday, June 04, 2011 6:14 PM
  • Hi,

    According to your description ,if you use the Navigation Framework and want to navigate to a login page, for my experience you can use NavigationService.Navigate Method to navigate asynchronously to content that is specified by a uniform resource identifier (URI) like this:

    NavigationService.Navigate(new Uri("/OtherViewPage.xaml", UriKind.Relative));

    In addition ,I would recommend that you can check the link below for an article which describes all about the concept of Navigation Framework.

    http://www.codeproject.com/Articles/180658/Navigation-Framework-in-Silverlight-4.aspx

    If you want to navigate to a web page via silverlight application, you can use the code as below:

    System.Windows.Browser.HtmlPage.Window.Navigate(new Uri("http://www.microsoft.com",UriKind.Absolute));

    when I am in a page aspx inside the frame of MainPage I have a comprobation in all inside pages and I want then change again the rootvisual for goes to the login page. How can I do this?

    Base on my understanding ,I would like to suggest you to create a function which is used to navigate the page in App.xaml.cs file as below:

    Grid rootvisual = new Grid();
            public void GotoPage(UserControl nextPage)
            {
                App app = (App)Application.Current;
                app.rootvisual.Children.Clear();
                app.rootvisual.Children.Add(nextPage);
            }
    
            private void Application_Startup(object sender, StartupEventArgs e)
            {
                this.RootVisual = rootvisual;
                rootvisual.Children.Add(new MainPage()); 
            }

    Then ,you can call this function to navigate page as you want like this:

    Code in silverlight page(.xaml.cs file):

    App app = (App)Application.Current; app.GotoPage(new PageClassName()); 

    Hope it can help you.

    Monday, June 13, 2011 4:37 AM
  • your code working but i refresh it come up with last main.xaml

    Saturday, September 03, 2011 6:22 AM
  • Hi,

    but i refresh it come up with last main.xaml

    Actually ,the silverlight application is integrated with a web page by using <object> elements, if the web page is refreshed(reload the <object> elements), a new silverlight application instance will be created. Thus ,the Main.xaml page will display after the web page being refreshed.

    You can also put a break point at Application_Startup event in App.xaml.cs file to detect the life cycle of a silverlight application.

    Hope it can help you.

    Sunday, September 04, 2011 10:34 PM
  • This worked

    Friday, March 02, 2012 1:55 AM
  • Sorry, this last point is not clear for me. Can you give example please.

    Thanks

    Tuesday, May 08, 2012 10:23 AM