.net - ScrollViewer 中的列表框

标签 .net xaml windows-phone-7

我不知道为什么这段代码工作正常:

<ScrollViewer Height="674" HorizontalAlignment="Left" VerticalAlignment="Top" Width="480" Margin="0,94,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
    <StackPanel>
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
        <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
    </StackPanel>
</ScrollViewer>

而这不会:
<ScrollViewer Height="674" HorizontalAlignment="Left" VerticalAlignment="Top" Width="480" Margin="0,94,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
    <ListBox Width="480" ItemsSource="{Binding ViewModel_ObservableCollection_Property_With_15_Items}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Grid Height="85">
                    <Button Content="custom control" VerticalAlignment="Center" Width="480" Height="70" />
                </Grid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</ScrollViewer>

ListBox 版本无法在 ScrollViewer 中显示所有项目。诀窍是什么?

最佳答案

您应该避免使用 ScrollViewer 来包装 ListBox,因为默认 ListBox 样式中已经有一个 ScrollViewer。

关于.net - ScrollViewer 中的列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7947657/

相关文章:

wpf - Windows Phone 7/Silverlight/WPF MVVM 开发

.net - 如何从 axd 转换为 ashx?

c# - HttpClient 没有正确序列化 XML

c# - 如何让 Entity Framework Code First 和可为空的外键属性工作?

.net - "{x:Static}"在 XAML 中是什么意思?

c# - XMLRead.Create(new StringReader) 是否提供读取非 unicode (BIG5) 的功能?

.net - 如何在应用程序域之间传递事件?

.net - 从 Mysql 异步加载图像到 WPF

xaml - Metro XAML-LayoutTransform在哪里?

windows-phone-7 - 如何使用数据绑定(bind) MVVM 设置列表选择器的 selectedItem