Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は持っていListBoxます。使用するlistBox.Items[0]と、このアイテムのデータコンテンツを取得できますが、このアイテムの高さを取得したいです。
ListBox
listBox.Items[0]
この情報を取得する方法は?
ありがとう!
VisualTreeHelper クラスを使用できますここ で例を見つけることができます。したがって、最初の要素だけが必要な場合は、次のように使用します。
VisualTreeHelper
var item = FindFirstElementInVisualTree<ListBoxItem>(listBox); var height = item != null ? item.ActualHeight : 0.0;
最初のものだけでなくチェックする必要がある場合は、そのメソッドを自由に変更するか、独自に記述してください。