如何在代码隐藏中还原最小化的Window? [英] How to restore a minimized Window in code-behind?

查看:105
本文介绍了如何在代码隐藏中还原最小化的Window?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在某种程度上是一个平凡的问题,但是在我看来WPF中没有内置的方法.似乎只有WindowState属性,它是一个枚举并没有帮助,因为在最小化之前我无法确定Window是处于Normal还是Maximized状态.

This is somewhat of a mundane question but it seems to me there is no in-built method for it in WPF. There only seems to be the WindowState property which being an enum does not help since i cannot tell whether the Window was in the Normal or Maximized state before being minimized.

当单击任务栏图标时,该窗口将按预期方式还原,并假定其处于先前状态,但是我似乎找不到任何定义的方法来执行该操作.

When clicking the taskbar icon the window is being restored just as expected, assuming its prior state, but i cannot seem to find any defined method which does that.

所以我一直在想我是否只是缺少一些东西,或者是否需要使用一些自定义的交互逻辑.

So i have been wondering if i am just missing something or if i need to use some custom interaction logic.

(我将发布当前解决方案作为答案)

推荐答案

不确定该方法是否适用于所有人,但我今天遇到了这个问题,并且团队中的某人建议"您尝试过 Normal "吗?

Not sure this will work for everybody, but I ran into this today and someone on the team suggested "have you tried Normal"?

结果证明他是对的.以下内容似乎可以很好地还原您的窗口:

Turns out he was right. The following seems to nicely restore your window:

if (myWindow.WindowState == WindowState.Minimized)
    myWindow.WindowState = WindowState.Normal;

那很好,如果需要,将窗口恢复到最大化.首先检查最小化状态似乎很关键,因为第二次调用 WindowState.Normal 会将窗口还原"到非最大化状态.

That works just fine, restoring the window to Maximized if needed. It seems critical to check for the minimized state first as calling WindowState.Normal a second time will "restore" your window to its non-maximized state.

希望这会有所帮助.

这篇关于如何在代码隐藏中还原最小化的Window?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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