How to get grid column width in pixels in WPF?

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

GridLength l=tip.basis.ColumnDefinitions[0].Width; 
+4
source share
3 answers

The ActualWidth property must contain the column width in pixels

MSDN Page

+3
source

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

So, in the example above, this 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 .

+1
source

Use the ActualWidth property to get the width. He imagines

Column width in device independent devices (1/96th inch per unit).

0
source

All Articles