我正在开发两个Windows 10 UWP商店应用程序,它们都包含一个ListView。我的问题是,当我调整页面大小并使其变小时,ListView不会改变大小。因此,ListView的一部分对用户来说变得无法访问。为了研究这个问题,我制作了一个非常简单的应用程序,并只更改了XAML代码。
以下是XAML代码的样子:
以下是XAML代码的样子:
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Height="600" Width="340"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="0,0,0,0">
<ListView x:Name="listView" HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch">
<TextBlock Text="Line 1"></TextBlock>
<TextBlock Text="Line 2"></TextBlock>
<TextBlock Text="Line 3"></TextBlock>
<TextBlock Text="Line 4"></TextBlock>
<TextBlock Text="Line 5"></TextBlock>
<TextBlock Text="Line 6"></TextBlock>
<TextBlock Text="Line 7"></TextBlock>
<TextBlock Text="Line 8"></TextBlock>
<TextBlock Text="Line 9"></TextBlock>
<TextBlock Text="Line 0"></TextBlock>
<TextBlock Text="Line 11"></TextBlock>
<TextBlock Text="Line 12"></TextBlock>
<TextBlock Text="Line 13"></TextBlock>
<TextBlock Text="Line 14"></TextBlock>
<TextBlock Text="Line 15"></TextBlock>
<TextBlock Text="Line 16"></TextBlock>
<TextBlock Text="Line 17"></TextBlock>
<TextBlock Text="Line 18"></TextBlock>
<TextBlock Text="Line 19"></TextBlock>
<TextBlock Text="Line 20"></TextBlock>
</ListView>
</Grid>
如何复制:
- 创建一个 Windows 10 应用程序
- 按上述方式修改主页面
- 运行程序
- 调整窗口高度,使其低于 ListView
- 尝试向下滚动至第 20 行
预期行为:
The ListView should be resized
Line 20 should be accessible
实际行为:
The ListView is not resized
Line 20 cannot be accessed
在使用UWP之前,我曾经在Windows API中编写过类似的程序,认为这应该很容易,但是在阅读了数天的MSDN文档并且在论坛上查找无果后,我意识到UWP背后一定有一些新的哲学原理超出了我的理解范围。可能是我错过了一些简单的东西。