简体   繁体   English

检查窗口是否在 UWP 中最小化

[英]Check if window is minimized in UWP

I am developing a UWP application for Windows 10. I want to show a message dialog box when user reduces the size of the window.我正在为 Windows 10 开发 UWP 应用程序。我想在用户缩小窗口大小时显示一个消息对话框。 As of now, I have tried to implement the feature using this link .截至目前,我已尝试使用此链接实现该功能。 My purpose is being fulfilled here except the message dialog appears when user either minimizes the window or changes its size.我的目的在这里得到了满足,除了当用户最小化窗口或更改其大小时会出现消息对话框。 I have also attached the code snippet below.我还附上了下面的代码片段。 Thank you.谢谢你。

private async void CoreWindow_SizeChanged(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.WindowSizeChangedEventArgs args)
        {
            var appView = ApplicationView.GetForCurrentView();
            MessageDialog messageDialog = new MessageDialog("");
            if (!appView.IsFullScreen)
            {
                if (!msgboxshown)
                {
                    messageDialog = new MessageDialog("To run the application smoothly, please maximize the window.");
                    msgboxshown = true;
                    await messageDialog.ShowAsync();
                    msgboxshown = false;
                }
            }
            args.Handled = true;
        }

My purpose is being fulfilled here except the message dialog appears when user either minimizes the window or changes its size.我的目的在这里得到了满足,除了当用户最小化窗口或更改其大小时会出现消息对话框。

When app minimizes, it will invoke EnteredBackground event, you could detect it and show your message dialog.当应用程序最小化时,它将调用EnteredBackground事件,您可以检测到它并显示您的消息对话框。

 public App() { this.InitializeComponent(); this.Suspending += OnSuspending; this.EnteredBackground += App_EnteredBackground; } private async void App_EnteredBackground(object sender, EnteredBackgroundEventArgs e) { var messageDialog = new MessageDialog("To run the application smoothly, please maximize the window."); await messageDialog.ShowAsync(); }

Update更新

As @Raymond Chen said, it looks os bug.正如@Raymond Chen 所说,它看起来是 os 错误。 So please use the above methods with caution.所以请谨慎使用上述方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM