Harry13
Harry13

Reputation: 743

WPF application window changes it's size

I have a WPF application for which the main window should be the same size all the time.

Therefore I set in the constructor:

Width = 1024;
Height = 768;    
ResizeMode = ResizeMode.NoResize;
WindowStyle = WindowStyle.None;
Top = screenBounds.Top;
Left = screenBounds.Left;
SizeToContent = SizeToContent.Manual;

screenBounds come from the Screen.PrimaryScreen in most cases.

I also subscribed to SystemEvents.DisplaySettingsChanged and redo the procedure above when the screen resolution changes.

In some rare cases this does not work and the application window is displayed in a different size (e.g. 768x556) but the screen resolution change event was not triggered. I have to mention that there is also a VNC host running on this system. So my questions: - What can cause a size change of a WPF window which is not detected by the screen resolution change event? - How can I force to keep the window the same position and size all the time?

Upvotes: 0

Views: 1286

Answers (2)

Tyress
Tyress

Reputation: 3653

My guess is something is manually setting the size in the code, but if you really want to prevent it from happening, I suggest you set:

this.MaxHeight = this.MinHeight = 768;  
this.MaxWidth =  this.MinWidth =  1024;

EDIT:

I found out that SystemEvents.DisplaySettingsChanged fires on a user changing the Display Settings. Try using SystemEvents.DisplaySettingsChanging which fires on any Display Setting change.

Upvotes: 1

Maksim Satsikau
Maksim Satsikau

Reputation: 1494

Set Max and Min height and width values?

Upvotes: 1

Related Questions