我将如何处理windows mobile 10的后退按钮和windows 10 tablet模式的后退按钮?我一直在寻找,但找不到任何示例。Windows 10 UAP后退按钮
20
A
回答
28
此主题是Guide to Universal Windows Platform apps中使用的示例之一。我强烈建议您在开始使用Universal应用程序时阅读这些内容。
对于页眉上的按钮,使用Windows.UI.Core.SystemNavigationManager并设置AppViewBackButtonVisibility属性以显示或隐藏按钮并处理BackRequested事件以执行导航。
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += (s,a) =>
{
Debug.WriteLine("BackRequested");
if (Frame.CanGoBack)
{
Frame.GoBack();
a.Handled = true;
}
}
连线了硬件后退按钮一样的,你在的Windows Phone 8.1做的,但您应检查PhoneContract(或个人类和方法),以确保它的存在:
if (ApiInformation.IsApiContractPresent ("Windows.Phone.PhoneContract", 1, 0)) {
Windows.Phone.UI.Input.HardwareButtons.BackPressed += (s, a) =>
{
Debug.WriteLine("BackPressed");
if (Frame.CanGoBack)
{
Frame.GoBack();
a.Handled = true;
}
};
}
6
下面的代码添加到您的App.xaml.cs,它会处理在桌面,平板电脑和移动导航(我测试了它在移动仿真器) 更好地突出差异和(由JEFF PROSISEHandling The Back Button In Windows 10 UWP Apps)解释
sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
rootFrame.Navigated += OnNavigated;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
// Register a handler for BackRequested events and set the
// visibility of the Back button
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
rootFrame.CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
}
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
private void OnNavigated(object sender, NavigationEventArgs e)
{
// Each time a navigation event occurs, update the Back button's visibility
SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
((Frame)sender).CanGoBack ?
AppViewBackButtonVisibility.Visible :
AppViewBackButtonVisibility.Collapsed;
}
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
// TODO: Save application state and stop any background activity
deferral.Complete();
}
private void OnBackRequested(object sender, BackRequestedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame.CanGoBack)
{
e.Handled = true;
rootFrame.GoBack();
}
}
}
相关问题
- 1. 自定义Windows 10 UWP后退按钮
- 2. Interaction.Behaviors在Windows 10 UAP
- 3. Windows 10移动UWP - 慢退按钮
- 4. Windows Phone 8:后退按钮
- 5. Windows Phone 8后退按钮
- 6. Windows 10托管应用程序的后退按钮
- 7. windows phone 10上的硬件后退按钮不起作用
- 8. 如何控制windows phone 10硬件后退按钮
- 9. Windows 10 UAP更改窗口大小
- 10. Windows 10 UAP - 编译数据绑定
- 11. 后退按钮
- 12. Windows Phone 7后退按钮问题
- 13. 在Windows Phone上中断后退按钮
- 14. Windows Phone - XNA游戏 - 后退按钮
- 15. 如何取消在Windows 10 UWP中按下后退按钮导航?
- 16. 应用按后退按钮当按下后退按钮
- 17. 后退按钮android
- 18. 普遍窗口后退导航按钮10的应用程序
- 19. PHP后退按钮
- 20. UINavigation后退按钮
- 21. UITableView后退按钮
- 22. Android后退按钮
- 23. 后退按钮NSPopover
- 24. Laravel后退按钮
- 25. Jquery后退按钮。
- 26. UiNavigationBar后退按钮
- 27. IFrame后退按钮
- 28. 后退按钮uinavigationcontroller
- 29. jQTouch后退按钮
- 30. Webview后退按钮
AppViewBackButtonVisibility应该放在哪里? MainPage contstructor不会为我做任何事情,也不会在App.xaml.cs中执行OnLaunched – robertk
它会自动进入标题栏:) – shady
有没有什么方法可以自定义后退按钮的背景颜色? –