2017-06-19 47 views
0

我在我的UWP應用程序中有ListView,並希望它設置顯示寬度的100%。Set ListView100%的屏幕寬度(UWP)

這是我在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%"

但它不工作?

我該如何做到這一點?

+0

不要設置爲ListView的寬度那麼它會佔用屏幕的100% –

+0

不,不需要100%@ VijayNirmal – Logan

+0

將你的'ListView'' Horizo​​ntalAlignment'改爲'Stretch'。 – AVK

回答

4
  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> 
+0

已經修復它。謝謝 – Logan