I am trying to get the width and height of a Silverlight ComboBox's dropdown window.
Unfortunately ActualWidth
and ActualHeight
are returning 0 always.
Asked
Active
Viewed 781 times
0

Dave Clemmer
- 3,741
- 12
- 49
- 72

phm
- 1,160
- 1
- 17
- 29
3 Answers
2
<ComboBox x:Name="comboBox" Height="20" Width="120">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel SizeChanged="StackPanel_SizeChanged"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
private void StackPanel_SizeChanged(object sender, SizeChangedEventArgs e)
{
var w= e.NewSize.Width;
var h= e.NewSizeHeight;
}
But it's not a good way.

Dave Clemmer
- 3,741
- 12
- 49
- 72

Nario
- 551
- 6
- 16
-
Thanks but I need the dropdown's size, not the comboboxes – phm Apr 14 '11 at 09:43
1
You can't get the actual size without actually rendering the popup. This implies that ActualSizes will be 0 if the popup is hidden. This is a consequence of WPF performing layout and rendering logic for you.
You could possibly get the popup's requested height by performing a Measure pass on the popup itself. If the popup hasn't been created yet, you're still in trouble though. (And it may not get created until the first time it's displayed.)

Greg D
- 43,259
- 14
- 84
- 117
0
I found a solution to this by myself: you have to set the popup's "IsOpen" to true before measuring, and then set it back to false. It's the only way I could make it work.

phm
- 1,160
- 1
- 17
- 29