我的UWP应用程序包含动态内容ListView
。我想启用ScrollView
当它的高度达到它运行的设备高度的末尾时(桌面/移动)。我不想设置ListView
的高度/最大高度。因为它应该按原样显示。
我试过如下。但它没有用。仅当指定ListView
的高度时才有效。
<Grid HorizontalAlignment="Stretch" >
<Grid.RowDefinitions >
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<ListView x:Name="ItemListView" Margin="0,0,0,0" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="Auto" >
<!--ListView ItemTemplate to fill-->
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="0" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".5*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width=".8*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.RowSpan="2">
<TextBlock Text="{Binding SerialNum}" TextAlignment="Center" />
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" >
<TextBlock Text="{Binding XX}" TextAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="2" Orientation="Vertical" >
<TextBlock Text="{Binding YY}" TextAlignment="Center" />
<TextBlock x:Name="tb_list_date" HorizontalAlignment="Center" Text="{Binding ZZ}" TextAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="3">
<TextBlock Text="{Binding AA}" TextAlignment="Center" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="4" Grid.RowSpan="2" VerticalAlignment="Center" HorizontalAlignment="Center" >
<TextBlock Text="{Binding BB}" TextAlignment="Center"/> </StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
答案 0 :(得分:0)
问题是Grid.RowDefinition
设置为Auto
高度。这使得行中的控件可以使用他们需要的任何高度。这会导致ListView
超出页面边界,因为它的高度实际上是列表的整个高度,所以它不会滚动(但是你看不到溢出)。
要解决此问题,请将Grid.RowDefinition
Height
更改为*
。这将为控件提供Grid
中所有可用空间,但不超过:
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
...
</Grid>