private void Window_Loaded(object sender, RoutedEventArgs e)
{
int nWidth = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
int nHieght = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
this.LayoutTransform = new ScaleTransform(nWidth / 1920, nHieght / 1080);
}
How to Scale WPF application according to screen resolution?
I make a WPF application in .Net Framework 4.7. I developed this application on my Laptop which has full HD resolution (1920*1080). My problem is when I run my application on a low resolution monitor (1366*768), my application don't scale up according to the screen resolution. I tried using Per monitor DPI and do some edit in my App.Manifest but still the problem.
2 answers
Sort by: Oldest
-
Petrus 【KIM】 456 Reputation points
Feb 1, 2021, 1:46 AM -
DaisyTian-1203 11,626 Reputation points
Feb 1, 2021, 2:26 AM You can set
Width
andHeight
of the window according to the device's dispaly resolution, you can set it like below:<Window x:Class="WPFScale.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:WPFScale" mc:Ignorable="d" Width="{x:Static SystemParameters.PrimaryScreenWidth}" Height="{x:Static SystemParameters.PrimaryScreenHeight}" Title="MainWindow"> <Grid> </Grid> </Window>
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.