Mixer
Mixer

Reputation: 1332

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

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;

Upvotes: 5

Views: 13572

Answers (3)

ywm
ywm

Reputation: 1127

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

MSDN Page

Upvotes: 3

Brian S
Brian S

Reputation: 5785

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.

Upvotes: 3

Haris Hasan
Haris Hasan

Reputation: 30097

Use the ActualWidth property to get the width. It represents

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

Upvotes: 0

Related Questions