设置ListView100%的屏幕宽度(UWP)

时间:2017-06-19 17:34:25

标签: c# xaml uwp

我的UWP应用程序中有ListView,并希望它设置100%的显示宽度。

这是我在xaml文件中的代码

<Page
x:Class="TestApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <ListView x:Name="PostList" ItemsSource="{Binding PostsList}" HorizontalAlignment="Left" Height="720" VerticalAlignment="Top" Width="1280">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid x:Name="GridInf"  Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,1,1">
            </Grid>
            </DataTemplate>
    </ListView.ItemTemplate>
    </ListView>
</Grid>

我尝试这样做Width="100%"

但它不起作用?

我怎么能成功?

1 个答案:

答案 0 :(得分:5)

  1. 不要设置ListView的宽度
  2. 设置HorizontalAlignment="Stretch"或不设置
  3. 这是您修改后的代码

    <ListView x:Name="PostList" ItemsSource="{Binding PostsList}" HorizontalAlignment="Stretch" Height="720" VerticalAlignment="Top">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Grid x:Name="GridInf"  Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,1,1">
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>