簡體   English   中英

設置ListView屏幕寬度的100%(UWP)

[英]Set ListView100% of screen width (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. 不要設置ListView的寬度
  2. 設置HorizontalAlignment="Stretch"或不設置

這是您修改的代碼

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM