how to set wpf MessageBox.Owner to desktop window because SplashScreen closes MessageBox

前端 未结 7 905
有刺的猬
有刺的猬 2020-12-16 00:30

I am using the SplashScreen feature in WPF by setting a bitmap\'s Build Action to Splashscreen. Behind the splash screen, licensing informa

7条回答
  •  生来不讨喜
    2020-12-16 00:36

    Can you post some code? I just tried adding this to the App.xaml.cs file in a new WPF application:

    protected override void OnStartup(StartupEventArgs e)
    {
        if (MessageBox.Show("Start app?", "Confirm Start", 
            MessageBoxButton.YesNo) == MessageBoxResult.No)
        {
            this.Shutdown();
            return;
        }
    
        this.StartupUri = new Uri("Window1.xaml", UriKind.Relative);
        base.OnStartup(e);
    }
    

    ... and it works as expected (the "Confirm Start" prompt stays open until I've responded, and if I click "No" the app shuts down).

提交回复
热议问题