In a UWP project (intended for PCs and tablets) I implemented a BackRequested, so that tablets can launch the 'back to previous page action' with the default button offered by tablets, via the following code: In the Page.xaml code of my page there is no change made. In the Page.xams.cs code:
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested;
...
}
private static async void BackRequested(object sender, Windows.UI.Core.BackRequestedEventArgs e)
{
e.Handled = true;
// code for Back action
}
This UWP code works great! I am migrating this code to WinUI-3. If the previous code compiles very well under WinUI-3, when running, there is a crash at the line:
Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += BackRequested;
The error message:
An unhandled exception of type 'System.AccessViolationException' occurred in Microsoft.Windows.SDK.NET.dll Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Is it possible to migrate this UWP code to WinUI-3, by making the minimum of modifications and especially without touching the Xaml code (because I have 4403 *.xaml files)!
Thanks in advance