无法一致地还原最小化的WPF应用程序 [英] Unable to consistently restore minimized WPF application

查看:76
本文介绍了无法一致地还原最小化的WPF应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WPF(C#)应用程序遇到奇怪的行为:

最小化应用程序之后,尝试通过单击任务栏中的图标来还原应用程序并不能始终如一地还原它.有时,它可以在几次鼠标单击后恢复,而有时甚至是在几次鼠标单击或全部恢复后恢复.

我尝试了StateChanged和SizeChanged事件处理程序都没有成功:

私有void Window_StateChanged(object sender,EventArgs e){

如果(this.WindowState == WindowState.Minimized)
this.WindowState = WindowState.Minimized;
其他
this.WindowState = WindowState.Normal;
}

感谢您提供任何见解.

I am running into a weird behaviour with a WPF (C#) application:

After minimizing the app, trying to restore the app by clicking on the icon in the task bar does not restore it consistently. Sometimes it restores after a couple mouse clicks and other times after several mouse clicks or not all.

I have tried both the StateChanged and SizeChanged event handler without success:

private void Window_StateChanged(object sender, EventArgs e){

if (this.WindowState == WindowState.Minimized)
this.WindowState = WindowState.Minimized;
else
this.WindowState = WindowState.Normal;
}

Any insights are appreciated.

推荐答案

对于您的理解:您显示的代码没有任何意义.如果什么都不做.它说:将其最小化,将其最小化".再次.如果已经最小化,则没有什么可以最小化的(开发人员足够聪明,可以通过检查当前状态是否与请求相同并忽略该属性的调用来避免堆栈溢出),它没有被最小化,event未触发.

—SA
For your understanding: the code you are showing makes no sense. If does nothing. It says: "it it minimized, minimize it". Again. If it is already minimized, there is nothing to minimize (developers are clever enough to avoid stack overflow you could get by checking that the current state is the same as requested and ignoring the call of the property), it it is not minimized, event is not triggered.

—SA


SA是正确的,如果将其最小化,则将其设置为最小化"完全没有意义.如果WPF不明智(这很可能),则确实可能导致堆栈溢出.因此,在状态更改事件中更改状态是有风险的.如果您摆脱了这段代码,它会改变什么吗?我怀疑不是.我们有一个WPF应用程序,但是我们创建了带有按钮的标题栏,从中可以设置窗口状态,并且它可以正常工作(它已经投放市场4年以上,并且有很多用户).

一个建议-您是否设置了鼠标捕获功能?如果捕获了鼠标,则可以单击按钮以最大化/最小化,并且单击不会被记录.这似乎是您解决此问题的一种可能方法.
SA is right, setting it to minimised if it is minimised, makes no sense at all. If WPF is not smart ( which is likely ) it could indeed cause a stack over flow. Changing a state in the state changed event is risky for that reason. If you get rid of this code, does it change anything ? I suspect not. We have a WPF app, but we create our own title bar with buttons that we set the Window State from, and it works fine ( it''s been on the market for 4 + years and has plenty of users ).

One suggestion - do you ever set the mouse capture ? If the mouse has been captured, you could click on the buttons to maximise/minimise and the clicks would not register. That seems a likely way for you to get this issue.


这篇关于无法一致地还原最小化的WPF应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆