Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:50:31+00:00 2026-06-11T07:50:31+00:00

I am developing a WPF application that will be displayed in a Full-HD LCD

  • 0

I am developing a WPF application that will be displayed in a Full-HD LCD screen (42 inch).
In addition, I need to accommodate the controls in absolute positions.
In the development environment I can not see a window in length 1920×1080 (this is the fixed resolution of the targeted screen).

What is the best practice to accomplish this task?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:50:33+00:00Added an answer on June 11, 2026 at 7:50 am

    WPF uses Device Independent Units for specifying width/heights/positions/thicknesses, etc.

    1 DIU/DIP = 1 physical pixel when your screen DPI is set to 96dpi…..but 1 DIU = a different number of physical pixels when the DPI is not 96dpi.

    If you use a Canvas then it positions elements using DIUs.

    Now you imply that you want to position absolutely in terms of pixel coordinates.

    So to do this with the Canvas no matter what the current DPI setting is, you have to use a scaling trick (you can do this with a ViewBox, or a LayoutTransform).

    The example below shows one way to achieve it (my screen is 1366×768….you can change it to Full HD).

    It looks at the DPI of the system and gets the Canvas scaled down whenever the DPI goes up. This allows you to use Canvas coordinates that really mean pixel coords.

    If you are able to change the users screen to 96dpi then there is no need to do the scaling trick because 1 DIU = 1 physical pixel at 96dpi…no rescaling needed.

    <Window x:Class="WpfApplication12.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            WindowStyle="None"
            AllowsTransparency="True" Background="White"
            SizeToContent="WidthAndHeight"
            Title="MainWindow" Loaded="Window_Loaded">
        <Viewbox x:Name="viewbox">
        <Canvas x:Name="canvas">
            <Rectangle x:Name="rect" Canvas.Top="10" Canvas.Left="10" Stroke="Red" StrokeThickness="1"/>
            <Button Canvas.Top="20" Canvas.Left="20">Test Button</Button>
                <Ellipse Canvas.Top="100" Canvas.Left="100" Width="100" Height="100" Stroke="Red" StrokeThickness="10"/>
                <TextBlock Canvas.Top="100" Canvas.Left="100" FontSize="15">Some Text</TextBlock>
            </Canvas>
        </Viewbox>
    </Window>
    

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication12
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            // HD
            const int screenwidth = 1366;
            const int screenheight = 768;
    
            // FULL HD
            //const int screenwidth = 1920;
            //const int screenheight = 1080;
    
            public MainWindow()
            {
                InitializeComponent();
    
                Top = 0;
                Left = 0;
    
                canvas.Width = screenwidth;
                canvas.Height = screenheight;
    
                rect.Width = screenwidth - 20;
                rect.Height = screenheight - 20;
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                bool bScaleBackToPixels = true;
    
                if (bScaleBackToPixels)
                {
                    PresentationSource presentationsource = PresentationSource.FromVisual(this);
                    Matrix m = presentationsource.CompositionTarget.TransformToDevice;
    
                    double DpiWidthFactor = m.M11;
                    double DpiHeightFactor = m.M22;
    
                    viewbox.Width = screenwidth / DpiWidthFactor;
                    viewbox.Height = screenheight / DpiHeightFactor;
                }
                else
                {
                    viewbox.Width = screenwidth;
                    viewbox.Height = screenheight;
                }
            }
        }
    }
    

    <Window x:Class="WpfApplication12.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            WindowStyle="None"
            AllowsTransparency="True" Background="White"
            SizeToContent="WidthAndHeight"
            Title="MainWindow" Loaded="Window_Loaded">
        <Canvas x:Name="canvas">
            <Rectangle x:Name="rect" Canvas.Top="10" Canvas.Left="10" Stroke="Red" StrokeThickness="1"/>
            <Button Canvas.Top="20" Canvas.Left="20">Test Button</Button>
                <Ellipse Canvas.Top="100" Canvas.Left="100" Width="100" Height="100" Stroke="Red" StrokeThickness="10"/>
                <TextBlock Canvas.Top="100" Canvas.Left="100" FontSize="15">Some Text</TextBlock>
            </Canvas>
    </Window>
    

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication12
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            // HD
            const int screenwidth = 1366;
            const int screenheight = 768;
    
            // FULL HD
            //const int screenwidth = 1920;
            //const int screenheight = 1080;
    
            public MainWindow()
            {
                InitializeComponent();
    
                Top = 0;
                Left = 0;
    
                canvas.Width = screenwidth;
                canvas.Height = screenheight;
    
                rect.Width = screenwidth - 20;
                rect.Height = screenheight - 20;
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                bool bScaleBackToPixels = true;
    
                if (bScaleBackToPixels)
                {
                    PresentationSource presentationsource = PresentationSource.FromVisual(this);
                    Matrix m = presentationsource.CompositionTarget.TransformToDevice;
    
                    double DpiWidthFactor = m.M11;
                    double DpiHeightFactor = m.M22;
    
                    double scalex = 1 / DpiWidthFactor;
                    double scaley = 1 / DpiHeightFactor;
    
                    canvas.LayoutTransform = new ScaleTransform(scalex, scaley);
                }
            }
        }
    }
    

    At the 96 DPI setting (Smaller – 100%) the screen looks like this:

    enter image description here

    At the 120 DPI setting (Medium – 125%) (i.e. 96 x 1.25 = 120DPI) the screen looks like this when using my ScaleBackToPixels technique above (i.e. it looks the same as the first screen).

    enter image description here

    At the 120 DPI setting (Medium – 125%) (i.e. 96 x 1.25 = 120DPI) the screen looks like this when you don’t do any adjustments at all (notice how the circle is bigger, and the font and size of the Button).

    enter image description here

    All 3 images side by side for comparison:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing WPF application which will be executing on the 21-inch touch-screen. Along
I am developing a desktop application that will need to collect data (from the
I am developing a WPF application that must run using Windows Classic theme. The
I am developing a WPF application that must meet Section 508 (Accessibility) requirements. In
I am developing a simple WPF Application that requires a database. My question is,
I am developing a WPF application, that connects to several WCF services (that work
I'm developing a desktop application in WPF, application that is manipulating a considerable amount
Context: I'm developing a WPF application which will contain a lot of different screens.
I am developing a WPF application, and I need your advice. I have to
We are developing a WPF application which uses Telerik's suite of controls and everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.