Skip to main content
Home Forums General Silverlight New Features in Silverlight 3 Codebehind in SL3 RIA Navigate - can't figure out the Uri string
3 replies. Latest Post by zvunks on November 1, 2009.
(0)
squeege
Member
10 points
31 Posts
08-25-2009 5:39 PM |
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
Star
9937 points
1,629 Posts
08-25-2009 7:35 PM |
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)); } }
08-25-2009 10:30 PM |
perfect thanks!
zvunks
7 points
3 Posts
11-01-2009 10:56 AM |
I'm also thanking you