简体   繁体   中英

ListBox vertical scroll bar not working in menu

I have a menu where I have to display several item types. Here is sample of the code of what I have for now:

   <Menu Height="23" HorizontalAlignment="Left" Margin="84,40,0,0" Name="menu1" VerticalAlignment="Top">
                    <MenuItem Header="(None)" IsTextSearchCaseSensitive="False" IsTextSearchEnabled="False">
                        <MenuItem Header="Aggregation">
                            <MenuItem Header="Sum"/>
                            <MenuItem Header="Average"/>
                        </MenuItem>
                        <Separator/>
                        <ListBox ScrollViewer.VerticalScrollBarVisibility="Visible" >
                            <MenuItem Header="Test0" IsCheckable="True"/>
                            <MenuItem Header="Test1" IsCheckable="True"/>
                            <MenuItem Header="Test2" IsCheckable="True"/>
                            <MenuItem Header="Test3" IsCheckable="True"/>
                            <MenuItem Header="Test4" IsCheckable="True"/>
                        </ListBox>
                        <Separator/>
                        <MenuItem Header="Test5" />
                    </MenuItem>
                </Menu>

If you notice, there is a ListBox there. I set the vertical scroll viewer to visible and it never activates no matter how many items I add. If you are wondering, yes, I tried with ListBoxItem instead of MenuItems and did not make a difference. Is there a different way to do this? How do I go about it? Thanks

You need to set a MaxHeight otherwise the ListBox will just stretch as much as it needs to display all of its elements.

<ListBox ScrollViewer.VerticalScrollBarVisibility="Visible" MaxHeight="250" />

That said, like AkselK commented, this does not look like good design.
You could simply keep on creating submenus.

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