[英]How to get listboxitem?
I have a ListBox
. 我有一个
ListBox
。 If I use listBox.Items[0]
I get this item datacontent, but I want to get this item's height. 如果我使用
listBox.Items[0]
,则获得此项目的数据内容,但我想获得此项目的高度。
How to get this information? 如何获得此信息?
Thx a lot! 多谢!
You can use a VisualTreeHelper
class You can find an example here . 您可以使用
VisualTreeHelper
类。您可以在此处找到示例。 So, if you need just first element - use it in this way: 因此,如果只需要第一个元素,请按以下方式使用它:
var item = FindFirstElementInVisualTree<ListBoxItem>(listBox);
var height = item != null ? item.ActualHeight : 0.0;
If you need to check not only the first one, feel free to modify that method or write you own. 如果您不仅需要检查第一个方法,请随时修改该方法或编写您自己的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.