1

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

1

1 Answer 1

0

Acccording to the document, SystemNavigationManager is not supproted in WinUI3. Those XxxForCurrentView methods have an implicit dependency on the ApplicationView type, which isn't supported in desktop apps. Because ApplicationView isn't supported in desktop apps, none of the XxxForCurrentView methods are supported either. Some unsupported XxxForCurrentView methods not only return null, but also throw exceptions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.