为什么我无法滚动我的ListBox

时间:2012-04-26 21:26:54

标签: windows-phone-7

任何人都知道为什么我不能用Grid滚动我的ListBox? 我找到的是添加此属性: ScrollViewer.VerticalScrollBarVisibility = “自动” 但在我的应用程序中,这不起作用

这是我的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 个答案:

答案 0 :(得分: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>

答案 1 :(得分:1)

Listbox确实内置了ScrollViewer;但是有些人可能会选择将ListBox包装在ScrollViewer中以便更顺畅地滚动。我会在Listbox中使用ItemTemplate。这些链接应该有所帮助:

谢谢!

答案 2 :(得分:0)

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

答案 3 :(得分:0)

感谢大家的建议。 这不起作用,因为我有两个列表框拼凑在一起。谢谢willmel;)

这应该是:

    <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>