Question

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.

Was it helpful?

Solution

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: enter image description here

Consult this topic for more info.

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top