Scale an entire WPF window

Just realized that putting the transform on the top-level control (a Grid, in my case), instead of on the window itself, has a similar effect to what I was looking for. The only difference is that the window size doesn't change so everything looks a little cramped, but that is easily remedied by making the window larger.


I posted a fairly detailed example of scaling the main element in another question. Perhaps it would be of some use to you.


Working Solution

At least in WPF .NET Core 3.1 Window supports SizeToContent="WidthAndHeight", it may work with older versions also as this property is supported since .NET Framework 3.0.
Combined with a fixed width/height of the content control and a ScaleTransform set on LayoutTransform, it scales the entire window.

Recipe

  • Window
    • SizeToContent: WidthAndHeight
  • Content
    • Fixed size
    • LayoutTransform: your custom ScaleTransform

Note

Setting SizeToContent by a style doesn't work (seems too late in the process).

Sample XAML

<Window x:Class="Some.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Some"
        mc:Ignorable="d"
        Title="MainWindow" 
        SizeToContent="WidthAndHeight"
        >
    <Window.Resources>
        <ResourceDictionary>
            <ScaleTransform x:Key="windowScaleTransform" ScaleX="0.5" ScaleY="0.5" />
        </ResourceDictionary>
    </Window.Resources>

    <Grid Width="1080" 
          Height="1920" 
          LayoutTransform="{StaticResource windowScaleTransform}"
          >
        <TextBlock>This window is scaled to 50%!</TextBlock>        
    </Frame>
</Window>


Using ViewBox would be the simplest way to make an entire application bigger, even the font size. Here you can find some discussion about ViewBox.