views:

1225

answers:

2
+3  Q: 

WPF Resize Windows

I maintain a touch screen application that I'm re-writing into .Net. Through the years the resolution of the touch screens has increased greatly. Not only is the resolution higher, but the pixels are also much more dense making it harder to see/operate the touch buttons.

Is there a way with WPF to force application windows to scale themselves larger as resolutions/pixel density changes? I'd rather not have to rework these screens every few years.

+3  A: 

Yes, there is.

You can wrap your container with WPF's ViewBox. Here goes the example:

<Window x:Class="TestWPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">

    <Viewbox Stretch="Uniform">
        <StackPanel Background="Azure" Height="400" Width="300" Name="stackPanel1" VerticalAlignment="Top">
            <Button Name="testBtn" Width="200" Height="50">
                <TextBlock>Test</TextBlock>
            </Button>
        </StackPanel>
    </Viewbox>

</Window>

Screenshot: http://lh6.ggpht.com/_5XDoB4MglkY/SU_uU8IjMHI/AAAAAAAAE1s/Wg5KQ8nrnhg/s800/Untitled.jpg

Consult this topic for more info.

m3rLinEz
Note: the Viewbox does not apply stretch to canvas components.
Jeff
+1  A: 

This is the default behavior, each WPF "pixel" is 1/96 of an inch and not an actual pixel (now the only problem is that virtually all screens are set to 96DPI regardless of the screen actual resolution).

Nir