【问题标题】:ListBox inside ScrollViewerScrollViewer 内的 ListBox
【发布时间】:2011-10-30 20:37:36
【问题描述】:

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

<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 中显示所有项目。有什么诀窍?

【问题讨论】:

    标签: .net xaml windows-phone-7


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      只需更改列表框的模板

      <ListBox.Template>
        <ControlTemplate TargetType="ListBox">
          <Border>
            <ItemsPresenter />
          </Border>
        </ControlTemplate>
      </ListBox.Template>
      

      【讨论】:

        猜你喜欢
        • 2011-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-30
        • 2010-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多