[英]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. 如果您注意到,那里有一个ListBox。 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.
如果您想知道,是的,我尝试使用ListBoxItem而不是MenuItems进行尝试,并且没有任何区别。 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. 您需要设置一个
MaxHeight
否则ListBox会按照显示其所有元素的需要进行拉伸。
<ListBox ScrollViewer.VerticalScrollBarVisibility="Visible" MaxHeight="250" />
That said, like AkselK commented, this does not look like good design. 就是说,就像阿克塞尔克(AkselK)所评论的那样,这看起来并不像好的设计。
You could simply keep on creating submenus. 您可以继续创建子菜单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.