Share via

WIN UI 3.0 issues

2026-02-16T06:24:41.54+00:00
  1. ContentDialog issue: In Winui 3.0, we do have Content Dialog to show (which doesn't behave like Modal dialog). Here, concern is, I can still go to the window behind and operate even though the content dialog is already popup. Any solution to freeze the back ‘entire’ window when this pops up?
  2. Application launch issue: We created a .net core 7.0 winui 3.0 desktop application, whenever we launch the application, it takes too much time (4 to 5 seconds and may extend to 10seconds based on machine performance)? Is there any solution to fix this? We work on MVVM architecture. After launching, the application sometimes freezes, we have to minimize & maximize the window to make it responsive.
  3. Application close button: We would like to handle the validations before the application closes when user clicks on 'X' button of application. Winui 3.0 doesn't have any event handling mechanism on close button. Can you suggest how to achieve this?
Windows development | WinUI
{count} votes

2 answers

Sort by: Most helpful
  1. Jack Dang (WICLOUD CORPORATION) 14,960 Reputation points Microsoft External Staff Moderator
    2026-02-16T08:10:29.8266667+00:00

    Hi @Rajashekaraiah, Bhadresh B SBOBNG-PTIY/ER ,

    Thanks for reaching out.

    1. ContentDialog behaving like a modal:

    To make sure a ContentDialog truly blocks the background window:

    • Always use await myDialog.ShowAsync() instead of Show().
    • Make sure the dialog is attached to the current, fully initialized window.
    • Avoid showing dialogs too early in the app startup; wait until the window is ready.

    Sometimes, even with ShowAsync(), the background may still be clickable if the dialog isn’t attached correctly or if multiple windows exist. If your dialog is triggered from a ViewModel, consider passing the window reference or raising an event to show the dialog from the View code.

    1. Application launch performance and freezing:

    Slow startup and temporary freezes usually happen when heavy initialization runs on the main UI thread. You can improve responsiveness by:

    • Offloading heavy tasks to background threads using async/await or Task.Run.
    • Showing the main window only after essential UI components are ready.
    • Profiling startup with Visual Studio’s performance tools to identify bottlenecks.
    1. Handling the close button (‘X’):

    WinUI 3 doesn’t provide a direct close event by default, but you can use the window’s Closing event or the AppWindow API to intercept closing. In that event, you can validate data or show a ContentDialog to confirm closing. If needed, cancel the close by setting args.Cancel = true.

    Here’s a reference example that combines all three ideas (keep in mind, this is just a starting point, you’ll want to adapt it to your MVVM setup and project structure):

    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
    
            // Hook into Closing event
            this.Closing += MainWindow_Closing;
    
            // Start async initialization
            InitializeAsync();
        }
    
        private async Task InitializeAsync()
        {
            // Simulate heavy startup work
            await Task.Run(() => {
                Thread.Sleep(2000); // replace with real initialization
            });
    
            // Show main window content
        }
    
        private async void MainWindow_Closing(object sender, WindowClosingEventArgs args)
        {
            // Show confirmation dialog before closing
            var dialog = new ContentDialog
            {
                Title = "Confirm Exit",
                Content = "Do you want to exit?",
                CloseButtonText = "No",
                PrimaryButtonText = "Yes"
            };
    
            var result = await dialog.ShowAsync(); // properly attached to window
    
            if (result != ContentDialogResult.Primary)
            {
                args.Cancel = true; // prevent closing
            }
        }
    
        private async void ShowModalDialog()
        {
            var dialog = new ContentDialog
            {
                Title = "Hello",
                Content = "This is a modal dialog.",
                CloseButtonText = "OK"
            };
    
            await dialog.ShowAsync(); // ensures modal behavior
        }
    }
    

    Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.

    1 person found this answer helpful.

  2. Q&A Assist
    2026-02-16T06:24:52.4166667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more
    1. ContentDialog Issue: In WinUI 3.0, the ContentDialog does not behave like a traditional modal dialog, which allows interaction with the underlying window. Unfortunately, there is currently no built-in way to freeze the entire window when a ContentDialog is open. The ContentDialog is designed to be shown modally relative to the root ApplicationView. If you need to prevent interaction with the underlying window, you may need to implement a custom solution or consider using a different approach for your dialog that ensures the background window is not interactable.
    2. Application Launch Issue: The slow launch time of your .NET Core 7.0 WinUI 3.0 desktop application could be due to several factors, including the complexity of the application, the initialization of resources, or the performance of the machine. To improve launch times, consider optimizing your application startup code, reducing the number of resources loaded at startup, or using asynchronous loading for non-essential components. Profiling your application during startup can also help identify bottlenecks.
    3. Application Close Button: In WinUI 3.0, there is no direct event handling mechanism for the close button (the 'X' button) on the application window. However, you can handle the Closing event of the Window to perform validations before the application closes. You can cancel the closing action if your validations fail, allowing you to prompt the user or take necessary actions before the application exits.

    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.