0

任何人都知道为什么我不能用 Grid 滚动我的 ListBox 吗?我发现只有添加此属性: ScrollViewer.VerticalScrollBarVisibility="Auto" 但在我的应用程序中这不起作用

这是我的 xaml 代码:

    <ListBox Height="776" ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="776"  Margin="11,12,0,0" Name="listBox1" Width="469">
        <ListBox>
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image Grid.Column="0" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="1" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="2" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="3" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="4" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="5" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="6" Source="/a;component/texture.png" />
                <Image Grid.Column="1" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
                </Grid>
        </ListBox>
    </ListBox>

感谢您的任何建议;)

4

4 回答 4

1

你有两个listboxes包裹在一起。看起来你真正想要的是一个ScrollViewer.

<ScrollViewer Margin="11,12,0,0" Name="listBox1" Width="469">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image Grid.Column="0" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="1" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="2" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="3" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="4" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="5" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="6" Source="/a;component/texture.png" />
                <Image Grid.Column="1" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
                </Grid>
        </ScrollViewer>
于 2012-04-26T21:39:11.653 回答
1

Listbox 确实有一个内置的 ScrollViewer;但是有些人可能会选择将 ListBox 包装在 ScrollViewer 中以实现更平滑的滚动。我会在列表框中使用 ItemTemplate。这些链接应该会有所帮助:

谢谢!

于 2012-04-27T02:26:39.813 回答
0

也将 scrollviewer 属性添加到内部列表框。

于 2012-04-27T05:23:07.420 回答
0

谢谢大家的建议。这不起作用,因为我将两个列表框包装在一起。谢谢威尔梅尔;)

这应该看起来像:

    <ListBox Height="776" ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="776"  Margin="11,12,0,0" Name="listBox1" Width="469">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Image Grid.Column="0" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="1" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="2" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="3" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="4" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="5" Source="/a;component/texture.png" />
                <Image Grid.Column="0" Width="200" Grid.Row="6" Source="/a;component/texture.png" />
                <Image Grid.Column="1" Width="200" Grid.Row="0" Source="/a;component/texture.png" />
                </Grid>
    </ListBox>
于 2012-04-28T13:34:39.337 回答