Home > DeveloperSection > Forums > Get the height/width of Window WPF
Mark Devid
Mark Devid

Total Post:102

Posted on    January-30-2014 11:08 PM


 1 Reply(s)
 7472  View(s)
Rate this:

I have the following code

<Window x:Class="Netspot.DigitalSignage.Client.MainWindow"



        Title="MainWindow" WindowStyle="SingleBorderWindow"


        WindowState="Normal" Closing="Window_Closing">

Any attempt to get the height / width return NaN or 0.0

Can anyone tell me a way of getting it ?

These 2 methods don't work


var h = ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight;

var w = ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth;


double dWidth = -1;

double dHeight = -1;

FrameworkElement pnlClient = this.Content as FrameworkElement;

if (pnlClient != null)


     dWidth = pnlClient.ActualWidth;

     dHeight = pnlClient.ActualWidth;


The application will not be running full screen.

Pravesh Singh

Total Post:412

Posted on    January-30-2014 11:31 PM

Hi Mark,

You can get the width and height that the window was meant to be in the constructor after InitializeComponent has been run, they won't return NaN then, the actual height and width will have to wait until the window has been displayed.

When WindowState == Normal You can do this one from Width / Height after IntializeComponent().

When WindowState == Maximized You could get the screen resolution for this one with



Don't want to miss updates? Please click the below button!

Follow MindStick