如何 Hide/Handle C# UWP App 框架中的后退按钮
How to Hide/Handle back button in C# UWP App frame
我有一个 UWP 应用程序,它的工作流程只有几个步骤。
- 第 1 步
- 第 2 步
- 第 3 步
- 第 4 步
假设第 4 步 作为最后一步,我想导航到第 2 步(而不是第 3 步)点击后退按钮最后一步(第 4 步)。
Step 4 -> (click back button) -> navigate to Step 2
如何处理我的 ViewModel 上的后退按钮单击事件?
或
如何隐藏 ViewModel 上的后退按钮?
到目前为止,我已经在我的 ViewModel 的构造函数上尝试了以下操作。
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
SystemNavigationManager.GetForCurrentView().BackRequested += (s, e) =>
{
// Handle the Back pressed
NavigateToStep2();
};
Previously, UWP apps used AppViewBackButtonVisibility for backwards navigation. The API will continue to be supported to ensure backward compatibility, but we no longer recommend relying on AppViewBackButtonVisibility. Instead, your app should draw its own in-app back button. See Navigation history and backwards navigation for UWP apps for more information.
根据您的描述,您的导航过程是高度定制化的。您需要制作自己的导航服务。在您的应用中,您还需要制作自己的应用内后退按钮并将该命令绑定到您的 ViewModel 的导航命令。
我用过Template10 in my project. It has implemented a NavigationService. I directly make my ViewModels inherit its ViewModelBaseclass来使用它的导航服务。很方便。您可以查看 Template10 源代码以获取更多详细信息。制作自己的导航服务会对您有所帮助。或者你也可以直接使用Template10 NavigationService。
我有一个 UWP 应用程序,它的工作流程只有几个步骤。
- 第 1 步
- 第 2 步
- 第 3 步
- 第 4 步
假设第 4 步 作为最后一步,我想导航到第 2 步(而不是第 3 步)点击后退按钮最后一步(第 4 步)。
Step 4 -> (click back button) -> navigate to Step 2
如何处理我的 ViewModel 上的后退按钮单击事件?
或
如何隐藏 ViewModel 上的后退按钮?
到目前为止,我已经在我的 ViewModel 的构造函数上尝试了以下操作。
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;
SystemNavigationManager.GetForCurrentView().BackRequested += (s, e) =>
{
// Handle the Back pressed
NavigateToStep2();
};
Previously, UWP apps used AppViewBackButtonVisibility for backwards navigation. The API will continue to be supported to ensure backward compatibility, but we no longer recommend relying on AppViewBackButtonVisibility. Instead, your app should draw its own in-app back button. See Navigation history and backwards navigation for UWP apps for more information.
根据您的描述,您的导航过程是高度定制化的。您需要制作自己的导航服务。在您的应用中,您还需要制作自己的应用内后退按钮并将该命令绑定到您的 ViewModel 的导航命令。
我用过Template10 in my project. It has implemented a NavigationService. I directly make my ViewModels inherit its ViewModelBaseclass来使用它的导航服务。很方便。您可以查看 Template10 源代码以获取更多详细信息。制作自己的导航服务会对您有所帮助。或者你也可以直接使用Template10 NavigationService。