嵌套列表框滚动问题

本文关键字:问题 滚动 列表 嵌套 | 更新日期: 2023-09-27 18:16:40

我在列表框中有一个列表框,当我试图降低窗口的高度时,列表框的滚动条没有出现。我想在外部列表框上显示滚动条,因为外部列表框可以有多个内部列表框。这是我正在使用的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>

嵌套列表框滚动问题

如果我没弄错的话,你肯定不希望内部列表框滚动。

有两种方法可以实现:

1)将内部列表框改为ItemsPanel。2)如果你真的需要保留内部控件作为ListBox,你必须在内部ListBox控件的模板中用ContentPresenter替换ScrollViewer。请看这个链接(它被标记为正确答案)> http://forums.silverlight.net/t/193872.aspx/1

将内部listbox更改为ItemsControl,则滚动条将不会显示在其中