xaml&中的后退按钮C# [英] A back button in xaml & C#

查看:83
本文介绍了xaml&中的后退按钮C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我现在一直在学习Xaml和C#。我使用一些基本的导航设计了一个应用程序但是我偶然发现了一个问题。例如,我为不同类型的用户创建了不同的仪表板。那些只能访问某些页面。这是一个例子:



我有一个名为用户管理的页面,可以查看应用程序中的所有用户。只允许用户A查看内容。在该页面中有一个创建按钮,这将导航用户A以创建新用户。问题是,用户B需要能够创建用户,但不应允许用户B点击后退按钮并访问只有用户A可以查看的用户管理屏幕。



我明白为什么会这样做。我只是不知道如何解决它。因此我正在学习这个事实...



以下是我使用当前后退按钮导航时使用的代码行:



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





什么我可以做到这一点,所以它总是引导你回到上一个屏幕? (另外,我不希望顶部有箭头的那个丑陋的导航栏。)我更喜欢让它尽可能干净。



如果有人在解释时可以给我一些额外的细节,那就太棒了!我比较新,希望这不是一项艰巨的任务..



谢谢!



我尝试了什么:



谷歌,YouTube,我不知道输入的确切关键词并且没有找到教程在这上面。

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.

推荐答案

在WPF导航中无法查看Back Stack页面。



你有很多不同的选择。这里有两个我的头脑:



1.当用户B登录时清除历史记录:
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:
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.自定义历史跟踪:



您需要挂钩到NavigationService事件并自己保持历史。然后,您可以回顾历史记录并发出 NavigationService.RemoveBackEntry(),以删除用户B不允许访问的页面。


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.


这篇关于xaml&amp;中的后退按钮C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆