获取最小化WPF窗口中点击 [英] Get the minimize box click of a WPF window

查看:513
本文介绍了获取最小化WPF窗口中点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得一个WPF窗口的最小化中点击事件?

How to get the minimize box click event of a WPF window?

推荐答案

有名为 StateChanged 这(从帮助)看起来像它可能会做你想要什么。

There's an event called StateChanged which (from the help) looks like it might do what you want.

发生时,窗口的的WindowState
属性的更改。

Occurs when the window's WindowState property changes.

帮助说,它仅支持在.NET 3.0和3.5在Vista下,但我刚在XP和它激发当窗口最小化,最大化和恢复。不过,从我的测试中,它触发的的状态已经改变,所以如果你想要做的最小,这可能不是你所需要的方法在窗口前的东西。

The help says it's only supported in .NET 3.0 and 3.5 under Vista, but I've just tried it on XP and it fires when the window is minimized, maximized and restored. However, from my testing, it fires after the state has changed, so if you want to do something before the window minimized this might not be the approach you need.

您必须检查的实际情况,以确保它是正确的。

You'll have to check the actual state to make sure it's correct.

    private void Window_StateChanged(object sender, EventArgs e)
    {
        switch (this.WindowState)
        {
            case WindowState.Maximized:
                MessageBox.Show("Maximized");
                break;
            case WindowState.Minimized:
                MessageBox.Show("Minimized");
                break;
            case WindowState.Normal:
                MessageBox.Show("Normal");
                break;
        }
    }

显然,如果我只是打印出状态我会使用 this.WindowState.ToString();)

下面应该得到加入到由Visual Studio的窗口的XAML确定指标:

The following should get added to the XAML defintion of your window by Visual Studio:

StateChanged="Window_StateChanged"

这篇关于获取最小化WPF窗口中点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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