我將如何處理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
有沒有什麼方法可以自定義後退按鈕的背景顏色? –