5

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;
Mixer
  • 1,292
  • 3
  • 22
  • 41

3 Answers3

3

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.

Community
  • 1
  • 1
Brian S
  • 5,675
  • 1
  • 22
  • 22
3

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

MSDN Page

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
ywm
  • 1,107
  • 10
  • 14
0

Use the ActualWidth property to get the width. It represents

The width of the column in device-independent units (1/96th inch per unit).

Haris Hasan
  • 29,856
  • 10
  • 92
  • 122