嵌套的ListBox滚动问题

3
我有一个列表框中嵌套了另一个列表框,当我试图减小窗口的高度时,内部列表框的滚动条不会出现。我希望在外部列表框上显示滚动条,因为外部列表框可能有多个内部列表框。 这是我使用的XAML。有人能告诉我问题出在哪里吗?
<ListBox Name="MasterListBox" HorizontalAlignment="Stretch" Width="200">
    <ListBoxItem >
        <ListBox Name="Child1" BorderBrush="{x:Null}">
            <ListBoxItem Content="testing item1" />
            <ListBoxItem Content="testing item2" />
            <ListBoxItem Content="testing item3" />
            <ListBoxItem Content="testing item1" />
            <ListBoxItem Content="testing item2" />
            <ListBoxItem Content="testing item3" />
            <ListBoxItem Content="testing item1" />
            <ListBoxItem Content="testing item2" />
            <ListBoxItem Content="testing item3" />
            <ListBoxItem Content="testing item1" />
            <ListBoxItem Content="testing item2" />
            <ListBoxItem Content="testing item3" />
            <ListBoxItem Content="testing item1" />
            <ListBoxItem Content="testing item2" />
            <ListBoxItem Content="testing item3" />
            <ListBoxItem Content="testing item1" />
            <ListBoxItem Content="testing item2" />
            <ListBoxItem Content="testing item3" />
        </ListBox>
    </ListBoxItem>

</ListBox>
2个回答

2
如果我理解正确的话,您不希望内部列表框滚动。

有两种方法可以实现这一点:

1)将内部列表框更改为ItemsPanel。 2)如果您确实需要保留内部控件作为ListBox,则必须在内部Listbox控件的模板中将ScrollViewer替换为ContentPresenter。请参见此链接(已标记为正确答案)> http://forums.silverlight.net/t/193872.aspx/1


如果我使用以下URL中提到的样式,它会在编译时出错,因为ContentPresenter不支持直接内容。 - amrit

1

将您的内部 listbox 更改为 ItemsControl,然后它就不会显示滚动条了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接