Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
682 views
in Technique[技术] by (71.8m points)

c# - Enable Maximize, Minimize and Restore Window in WPF (Manual Resize is disable)

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

  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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've finally found a relatively decent solution.

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);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...