Working with an oversized form window

176 views Asked by At

Recently I stumbled across an issue while working on a custom WPF form. (aren't they all custom anyway?). I added the following properties to the XAML.

AllowsTransparency="True"
ResizeMode="NoResize"
Height="945"
Width="1621" 
WindowStyle="None"

As well as a custom background image with the size listed above:

<Window.Background>
    <ImageBrush ImageSource="Images/form_bg.png" />
</Window.Background>

And after running it, some buttons which I had added, simply vanished. It wasn't until after I supersized the buttons (approx 300 height & width) that they started to appear.

It took me a little while trying to figure out what was going on.... Windows was resizing my form because it did not fit on my 15" laptop! Being only 1366 x 768, my Windows 8.1 simply resized the form, shrinking it to, I think, 70% of its original size. Since my controls use margins, and the XAML code was left untouched, but the actual form size reduced, my controls simply collapsed.

Now the obvious solution would be to make the image smaller, perhaps cropping it up a bit. Let's take 1280x1024 as a common resolution and make that fit. However, what if someone using a 1024x768 monitor runs that and it screws up on his end?

I managed to fix Windows' resizing by adding the MinWidth and MinHeight properties and setting them to the same values as Width & Height, but after moving the form, some of the bottom content simply drops off screen.

So, what I'm looking for is a proper way to deal with this. A decent user friendly solution. If perhaps I could have my controls resize along, the user might have trouble reading some of the content on a small screen.

Alternatively, perhaps I could maintain focus on a portion of the window using C#, regardless of its position? As long as that portion does not drop off screen that is.

Any tips, hints & samples greatly appreciated!

1

There are 1 answers

0
razblack On

If I understand your issue, being able to design a layout that scales regardless of the resolution?

One thing that I have done is to layout a grid over the window that uses "star" unit layout (basically percentage based) and within those grids, placed my user controls into a Viewbox. This allows me to set either a verticle and/or horizontal stretch to it within the grid. The controls will automagically scale within the viewbox, within the grid layout. This way, regardless of the resolution or scale of the display, the layout and controls will adjust accordingly.

If you need to have a static margin around the controls.. those rules will apply. If you need to create some type of limit to the scale you may need to create a dependency property that calculates the needed sizes of the controls and bind their width and heights to your results.