5

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?

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
Nir
  • 371
  • 2
  • 4
  • 12
  • 2
    By adding the window properities `Height="1024" Width="768" ResizeMode="CanMinimize"` you can achieve all but point 2. – ChrisF Feb 01 '10 at 12:29
  • Can you tell us why you want to fix the window at a certain size? It might help us think of some solutions. – Benny Jobigan Feb 02 '10 at 11:52
  • I'm working on a medical program that presents a medical image. The legacy program had a fixed size of 1024*768. Hence for old customers we need to preserve it as a basic resolution. We want to to have the option of maximizing the window so that we can check the program under certain sets of resolutions with no need to test the quality of the presented image in case the user resizes the application into non-standard size – Nir Feb 02 '10 at 14:22

2 Answers2

7

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);
    }
Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
Nir
  • 371
  • 2
  • 4
  • 12
0

You can listen to the Window.SizeChanged event, and inside your handler manually set Width and Height back to 1027 and 768. It still allows the user to drag the window's edges to resize, but then the window returns to it's set size. The drawback of this is that the window has a "seizure" whenever the user tries resizing--not the prettiest thing to see. Minimize and Maximize work as normal.

Benny Jobigan
  • 5,078
  • 2
  • 31
  • 41
  • Thanks, I already tried that one. The flickering ("Seizure") I encountered (as you said) made me left this idea in the beginning. – Nir Feb 02 '10 at 14:23