Search code examples
mauimaui-blazor

Disable F5 refresh in .Net Maui Blazor application


What will be proper way to disable refreshing of app by hitting F5 in .net7 windows targeted maui-blazor app.

With .net7.0 we are able to develop maui-blazor application targeting windows platform.

Visual studio nicely pack app which looks like native windows app, only issues so far is that windows app refresh itself on F5 key, from browser native functionality there is also search on F3 but that is not an issue.


Solution

  • Another way is to set AreBrowserAcceleratorKeysEnabled to false in Loaded event of MainPage.

    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            Loaded += MainPage_Loaded;
            
        }
        private async void MainPage_Loaded(object sender, EventArgs e)
        {
    
            #if WINDOWS
                var webView2 = (blazorWebView.Handler.PlatformView as Microsoft.UI.Xaml.Controls.WebView2);
                await webView2.EnsureCoreWebView2Async();
                webView2.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
           #endif
        }
    }