Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Okay, so I have been learning Xaml and C# for a little now. I designed a application using some basic navigation however I've stumbled into a problem. So for instance I created different dashboards for different types of users. Those only have access to certain pages. Here is an example:

I have a page called user management that views all users within the application. Only user A should be allowed to view the contents. In that page there is a create button, this navigates user A to create a new user. Well the problem is, user B needs to be able to create a user but user B should not be allowed to to hit the back button and gain access to the User management screen that only User A can view.

I understand why it does it. I just don't know of a way to work around it. Hence the fact I'm learning...

Here is the line of code I use when I navigate using my current back button:

this.NavigationServices.Navigate(new Views.UserManage.xaml());


What can I do to make it so it always refers you back to the previous screen? (Also I don't want that ugly navigation bar at the top that has the arrow.) I prefer to make it as clean as possible.

If someone can give me some extra detail when explaining it that would be great! I am relatively new and hopefully it won't be a huge task..

Thanks!

What I have tried:

Google, YouTube, I don't know exact key words to type in and haven't found a tutorial on this.
Posted
Updated 23-Mar-17 19:16pm

1 solution

There is no way in WPF Navigation to look at the Back Stack of pages.

You have a number of different choices. Here are two off the top of my head:

1. Clear history when "User B" logs in:
C#
public void ClearHistory()
 {
     if (!this.Frame.CanGoBack && !this.Frame.CanGoForward)
     {
         return;
     }

     var entry = this.Frame.RemoveBackEntry();
     while (entry != null)
     {
          entry = this.Frame.RemoveBackEntry();
     }

     this.Frame.Navigate(new PageFunction<string>() { RemoveFromJournal = true });
}

2. Custom History tracking:

You would need to hook into the NavigationService events and keep a history yourself. Then you can peek back into the history and issue a NavigationService.RemoveBackEntry() to remove the page that "User B" is not allowed access to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900