An ItemsControl in a Combobox Dropdown is not showing Vertical Scrolbar

Sep 2, 2009 at 3:50 PM

Hi there,

I want to display several listboxes in a combobox dropdown based on the bound model.

But when these list boxes hold list of large number of items they obviously go beyond the monitor screen height, but although my itemscontrol has a ScrollViewer.VerticalScrollBarVisibility="Visible" / "Auto" it doesnt work.

Can some one explain me what more should I be doing more to display a vertical scrollbar when this dropdwon's size is more than screen's height?

<Window x:Class="Window3"
        <ComboBox x:Name="cmbTest" Loaded="ComboBox_Loaded" ItemsSource="{Binding}">
                <Grid x:Key="lstBox" ScrollViewer.VerticalScrollBarVisibility="Auto">                     
                    <ItemsControl ItemsSource="{Binding}" ScrollViewer.VerticalScrollBarVisibility="Visible">
                                <ListBox ItemsSource="{Binding Path=RelatedNumbers}">
                                            <TextBlock Text="{Binding}"/>

And my code behind is ....

Partial Public Class Window3

    Private Sub ComboBox_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim a As New List(Of TestMe)
        For i As Integer = 1 To 5
            a.Add(New TestMe)
            For j = i To i * 5
                a(a.Count - 1).RelatedNumbers.Add(j)
        Me.DataContext = a
        Dim _popUp As Primitives.Popup = CType(cmbTest.Template.FindName("PART_Popup", cmbTest), Primitives.Popup)
        _popUp.Child = cmbTest.Resources("lstBox")
        _popUp.Width = cmbTest.ActualWidth
    End Sub

End Class

Public Class TestMe
    Private _lstNumbers As New List(Of Integer)
    Public ReadOnly Property RelatedNumbers() As List(Of Integer)
            Return _lstNumbers
        End Get
    End Property
End Class