启用最大化,最小化和WPF还原窗口(手动调整尺寸为禁用) [英] Enable Maximize, Minimize and Restore Window in WPF (Manual Resize is disable)

查看:2903
本文介绍了启用最大化,最小化和WPF还原窗口(手动调整尺寸为禁用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让我的应用程序如下(C#WPF应用程序):

I need to enable the following on my application (C# WPF application):


  1. 拥有1024 * 768的正常大小

  2. 用户可以最大限度的应用程序

  3. 用户可以最大限度地减少应用程序

  4. 用户可以恢复应用程序(1024 * 768)

  5. 的用户不能手动draging其边框调整应用程序。

  1. Have normal size of 1024*768
  2. The user can maximize the application
  3. The user can minimize the application
  4. The user can restore the application (1024*768)
  5. The user cannot manually resize the application by draging its border.

有没有任何 ResizeMode 的满足所有这些要求。有没有办法做到呢?

There isn't any ResizeMode the fulfills all of those requirements. Is there any way to do do?

推荐答案

我终于找到了一个比较体面的解决办法。

I've finally found a relatively decent solution.

我们的想法是在此改变窗口的 OnStateChanged 事件,取消最小/最大限制和刷新。

The idea is to overide the OnStateChanged event of the window, cancel the Min/Max constraints and refresh it.

如果没有最大化窗口,我们简单地套用回最小/最大限制

If the window is not maximized, we simply apply back the Min/Max constraints

    protected override void OnStateChanged(EventArgs e)
    {
        if (WindowState == WindowState.Maximized)
        {
            MinWidth = 0;
            MinHeight = 0;
            MaxWidth = int.MaxValue;
            MaxHeight = int.MaxValue;

            if (!m_isDuringMaximizing)
            {
                m_isDuringMaximizing = true;
                WindowState = WindowState.Normal;
                WindowState = WindowState.Maximized;
                m_isDuringMaximizing = false;
            }
        }
        else if (!m_isDuringMaximizing)
        {
            MinWidth = 1024;
            MinHeight = 768;
            MaxWidth = 1024;
            MaxHeight = 768;
        }

        base.OnStateChanged(e);
    }

这篇关于启用最大化,最小化和WPF还原窗口(手动调整尺寸为禁用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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