How to provide better resolution support?

Jun 1, 2008 at 9:00 AM
The main window was designed on a screen with 1600x1200 resolution (96 DPI). I expected WPF to provide easy support for resolution changes (since the design was vector based, and no raster images were used).
It turned out that this isn't the case. When viewing the program under lower resolution it didn't scale automatically.
I first tried the RenderTransform capabilities. I've added a ScaleTransform which reduces the drawing size by the scale factor in which the resolution changed.
It turned out that the drawing looked great, but the layout got screwed up. (Cards were drawn over the text, and so on...)
Next I tried to use the LayoutTransform capabilities. The same scale transform was used. It had a bit of work done, and a bit of trial & error needed.
This is the current solution which is implemented (It still doesn't look as good as expected in lower resolutions):

private void fixResolution()
            System.Windows.Forms.Screen mainScreen = System.Windows.Forms.Screen.PrimaryScreen;
            PresentationSource source = PresentationSource.FromVisual(this); 
            Matrix tfd = source.CompositionTarget.TransformFromDevice;
            double screenHeight = mainScreen.Bounds.Height;
            double screenWidth = mainScreen.Bounds.Width;
            double scaleFactor = 1;
            double curWidth = 0, curHeight = 0;
            for (int i = 0; i < scaleResolutions.Length; ++i)
                curWidth = scaleResolutions[i][0];
                curHeight = scaleResolutions[i][1];
                scaleFactor = scaleFactors[i];

                if (screenHeight >= curHeight && screenWidth >= curWidth)

            // can't suspend layout, I'll just hide for now...

            Left = designedLeft * tfd.M11;
            Top = desginedTop * tfd.M22;
            Width = (curWidth - designedWidth) * tfd.M11;
            Height = (curHeight - designedHeight) * tfd.M22; 

            double scaleX = scaleFactor * tfd.M11;
            double scaleY = scaleFactor * tfd.M22; 

            layoutTransform.ScaleX = scaleX;
            layoutTransform.ScaleY = scaleY;



This solution gets the user screen bounds, it searches for the proper scale factor and reduces the window borders to the desired size.
The layout transform is applied with the scale factor which will draw the internal layout with the correct window size. DPI corrections are preformed using the
TransformFromDevide matrix.