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 3949012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:26:35+00:00 2026-05-20T01:26:35+00:00

Is it a good practice to find the workarea measurement and set some properties

  • 0

Is it a good practice to find the workarea measurement and set some properties in code so that it could be bound to Control’s margin or height/Width properties in xaml?

I do this so that my window would resize according to the available workarea.

const int w = SystemParameters.WorkArea.Width;
const int h = SystemParameters.WorkArea.Height;

public Thickness OuterGridMargin { get; }

MainViewModel()
{
    OuterGridMargin = new Thickness(w/5,h/6,w/5,h/4);
}

xaml:

<Grid Margin="{Binding OuterGridMargin}" />

I do this for some outer containers so that the layout would not be messed in lower resolutions. Currently I work at 1600×900 res(96 dpi) in a 20″. My application is gadget like and does not have the regular window.

I want to know if there are some alternative approaches.

A search of [wpf] resolution]1 gives a lot of questions addressing similar problem but still I’m stuck and not able to come to a conclusion how to achieve a good resolution-independent layout.

  • 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-05-20T01:26:35+00:00Added an answer on May 20, 2026 at 1:26 am

    There are two ways to deal with resolution in WPF.

    One option is to design to a minimum resolution and just make sure everything is docked appropriately so that the elements get larger as the Window resolution gets larger. This is how many people did things in WinForms and still works decently well for WPF. You probably already have some concept of how to deal with this by setting HorizontalAlignment, VerticalAlignment, and margins.

    The newer, trendier thing to do in WPF that was nearly impossible to do in WinForms is have your application actually just zoom in so your controls get bigger as your Window does. To do this, you’ll apply a ScaleTransform on some root element in your Window and let WPF take care of the rest. It’s really cool.

    To show what this is like, here’s what a window would look like when you start the app, make it smaller, and make it bigger: https://i.stack.imgur.com/QeoVK.png

    Here’s the code-behind for the small sample app I made:

    public partial class MainWindow : Window
    {
        public MainWindow() => InitializeComponent();
    
        #region ScaleValue Depdency Property
        public static readonly DependencyProperty ScaleValueProperty = DependencyProperty.Register("ScaleValue", typeof(double), typeof(MainWindow), new UIPropertyMetadata(1.0, new PropertyChangedCallback(OnScaleValueChanged), new CoerceValueCallback(OnCoerceScaleValue)));
    
        private static object OnCoerceScaleValue(DependencyObject o, object value)
        {
            MainWindow mainWindow = o as MainWindow;
            if (mainWindow != null)
                return mainWindow.OnCoerceScaleValue((double)value);
            else return value;
        }
    
        private static void OnScaleValueChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            MainWindow mainWindow = o as MainWindow;
            if (mainWindow != null)
                mainWindow.OnScaleValueChanged((double)e.OldValue, (double)e.NewValue);
        }
    
        protected virtual double OnCoerceScaleValue(double value)
        {
            if (double.IsNaN(value))
                return 1.0f;
    
            value = Math.Max(0.1, value);
            return value;
        }
    
        protected virtual void OnScaleValueChanged(double oldValue, double newValue) { }
    
        public double ScaleValue
        {            
            get => (double)GetValue(ScaleValueProperty);
            set => SetValue(ScaleValueProperty, value);
        }
        #endregion
    
        private void MainGrid_SizeChanged(object sender, EventArgs e) => CalculateScale();
    
        private void CalculateScale()
        {
            double yScale = ActualHeight / 250f;
            double xScale = ActualWidth / 200f;
            double value  = Math.Min(xScale, yScale);
    
            ScaleValue = (double)OnCoerceScaleValue(myMainWindow, value);
        }
    }
    

    And the XAML:

    <Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" 
        Name="myMainWindow"
        Width="200" Height="250">
    <Grid Name="MainGrid" SizeChanged="MainGrid_SizeChanged">
        <Grid.LayoutTransform>
            <ScaleTransform x:Name="ApplicationScaleTransform"
                            CenterX="0"
                            CenterY="0"
                            ScaleX="{Binding ElementName=myMainWindow, Path=ScaleValue}"
                            ScaleY="{Binding ElementName=myMainWindow, Path=ScaleValue}" />
        </Grid.LayoutTransform>
        <Grid VerticalAlignment="Center" HorizontalAlignment="Center" Height="150">
            <TextBlock FontSize="20" Text="Hello World" Margin="5" VerticalAlignment="Top" HorizontalAlignment="Center"/>
            <Button Content="Button" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
        </Grid>
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What are some good desktop application projects I could code up that would be
Every release I find it a good practice to go back and grab all
I'm trying to find a good organization practice of my javascript (jquery) files when
Where can I find some good pointers on best practices for running ASP.NET MVC
Is it good practice to have a class constructor that uses default parameters, or
Is it good practice to have a unit test that specifies how long a
Is it good practice to create a class like the one below that can
It is generally considered good practice to add some lines with author, version and
I am wondering is it good practice to try to make a view that
I have a simple question: is a good practice to find a connect Bonjour

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.