XAML 在StackPanel/ScrollViewer中使用网格视图/列表视图

wsewodh2  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(100)

我有一个页面有多个控件类似于这个垂直:

TextBlock
Some Images
TextBlock
Some Images
ListView

TextBlock和Images的高度超过了屏幕的高度,因此我需要放一个这样的滚动查看器:

<ScrollViewer>
    <Grid>
          <Grid.RowDefinitions>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="Auto"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
          </Grid.RowDefinitions>
          <TextBlock Grid.Row="0" Text=...></TextBlock>
          <Image Grid.Row="1" Source=...></Image>
          <ListView Grid.Row="2"></ListView>
    </Grid>
</ScrollViewer>

它会导致一个问题,因为滚动查看器将击败列表视图的虚拟化(列表视图有~200个项目)。
是否有任何方式我可以把ListView作为网格的最后一个元素:

  • 具有快速性能
  • 显示所有行(不想设置ListView的MaxHeight,因为2个ScrollViewer会混淆)
  • 页面只有一个垂直滚动条
n6lpvg4x

n6lpvg4x1#

使用ListView作为页面的根,并利用ListView.Header作为顶部滚动内容。

<ListView>
   <ListView.Header>
      <StackPanel>
          <TextBlock />
          <Image />
      </StackPanel>
    </ListView.Header>
</ListView>

或者,您也可以使用ListView.HeaderTemplateListView.Header的组合来完成此操作。

相关问题