简体   繁体   中英

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

列宽以不同方式指定(星形,自动等)如何获取特定列的宽度(以像素为单位)?

GridLength l=tip.basis.ColumnDefinitions[0].Width;

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 .

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

MSDN Page

Use the ActualWidth property to get the width. It represents

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM