Skip to main content

Microsoft Silverlight

Answered Question Codebehind in SL3 RIA Navigate - can't figure out the Uri stringRSS Feed

(0)

squeege
squeege

Member

Member

10 points

31 Posts

Codebehind in SL3 RIA Navigate - can't figure out the Uri string

I modified "MainPage.XAML" in the July 09 RIA Business Application template so that when the user logs out, he is automatically taken back to the "home" page.

I've searched many sites and tried a bunch of stuff.  Does anybody actually know how to do this?  Thanks!

Code:

 
        public MainPage()
        {
            InitializeComponent();
            this.loginContainer.Child = new LoginControl();
            RiaContext.Current.Authentication.LoadUser().Completed += new EventHandler(MainPage_Completed);
            RiaContext.Current.Authentication.LoggedOut += new EventHandler(Authentication_LoggedOut);
        }
        
        void Authentication_LoggedOut(object sender, System.Windows.Ria.ApplicationServices.AuthenticationEventArgs e)
        {
            RedirectHomeOnLogout = true;
            RiaContext.Current.Authentication.LoadUser().Completed += new EventHandler(MainPage_Completed);
        }
        
        void MainPage_Completed(object sender, EventArgs e)
        {
			// other settings removed for simplicity...
            if (RedirectHomeOnLogout) //because this event may happen for other reasons in code I have removed for simplicity...
            {
                RedirectHomeOnLogout = false;
                ContentFrame.Navigate(new Uri("/Views/Home.xaml",UriKind.RelativeOrAbsolute));
                //I've tried "Views/Home.xaml", "Home.xaml", "/Views/Home.xaml"... and UriKind.(all the permutations)
                //and the error is always "Page Not Found (and then whatever I've supplied as the Uri string)"
            }
        }
  

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP
Answered Question

Re: Codebehind in SL3 RIA Navigate - can't figure out the Uri string

The value to use depends on the UriMapper that is defined in your frame on the Main Page. The default one has these entries:

<navigation:Frame.UriMapper>
  <uriMapper:UriMapper>
    <uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
    <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
  </uriMapper:UriMapper>
</navigation:Frame.UriMapper>

 This means that if you want to navigate to /Views/Home.xaml you would pass in /Home which would get translated to /Views/Home.xaml. So this should work:

void MainPage_Completed(object sender, EventArgs e)
{
  // other settings removed for simplicity...
  if (RedirectHomeOnLogout) //because this event may happen for other reasons in code I have removed for simplicity...
  {
    RedirectHomeOnLogout = false;
    ContentFrame.Navigate(new Uri("/Home",UriKind.Relative));
  }
}
 

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

squeege
squeege

Member

Member

10 points

31 Posts

Re: Re: Codebehind in SL3 RIA Navigate - can't figure out the Uri string

perfect thanks!

zvunks
zvunks

Member

Member

7 points

3 Posts

Re: Re: Re: Codebehind in SL3 RIA Navigate - can't figure out the Uri string

I'm also thanking you

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities