Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a Grid column width in pixels in WPF?

Tags:

c#

width

wpf

pixels

Column widths are specified in different ways (Stars, Auto etc) How to get the width in pixels of a specific column?

GridLength l=tip.basis.ColumnDefinitions[0].Width;
like image 645
Mixer Avatar asked Feb 15 '13 16:02

Mixer


2 Answers

You can use the ActualWidth or ActualHeight property of elements to get the width/height of elements. This answer describes the difference between `'ActualWidth' and 'Width'.

So in the above example it would be:

Double width = tip.basis.ColumnDefinitions[0].ActualWidth;

And also keep in mind that WPF uses Device Independent Pixels, as described in this answer.

like image 116
Brian S Avatar answered Sep 18 '22 01:09

Brian S


The ActualWidth property should provide the width of the column in Pixels

MSDN Page

like image 44
ywm Avatar answered Sep 20 '22 01:09

ywm