2016-05-23 38 views
-1

这里我的XAML代码XAML如何在一列中显示gridview?

<Page 
x:Class="GridView_Test.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:GridView_Test" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:data="using:GridView_Test.Model" 
mc:Ignorable="d" > 
<Page.Resources> 
    <DataTemplate x:DataType="data:Song" x:Key="SongItemTemplate" > 
     <StackPanel HorizontalAlignment="Stretch" Width="auto"> 
      <Image Source="{x:Bind ThumbImage}" Width="150" HorizontalAlignment="Center" /> 
      <TextBlock FontSize="16" Text="{x:Bind Title}" HorizontalAlignment="Center" /> 
      <TextBlock FontSize="12" Text="{x:Bind Author}" HorizontalAlignment="Center" /> 
     </StackPanel> 
    </DataTemplate> 
</Page.Resources> 
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="100" /> 
    </Grid.RowDefinitions> 
    <GridView ItemsSource="{x:Bind Songs}" Name="grid1" ItemTemplate="{StaticResource SongItemTemplate}" > 

    </GridView> 
</Grid> 

How it looks now

我需要做的项目在一列,像列表视图。默认情况下,在gridview项目中显示如表中所示,我需要一个列表。谢谢。

+0

你为什么不只是使用一个ListView那么代码? – Bart

+0

@Bart谢谢,效果很好。如何使用堆栈面板填充所有listview?使100%宽度? –

回答

0

我认为它是这样显示的,因为gridview需要分配给一些?添加Grid.Row属性的GridView的如下图所示

<Page 
x:Class="GridView_Test.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:GridView_Test" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:data="using:GridView_Test.Model" 
mc:Ignorable="d" > 
<Page.Resources> 
    <DataTemplate x:DataType="data:Song" x:Key="SongItemTemplate" > 
     <StackPanel HorizontalAlignment="Stretch" Width="auto"> 
      <Image Source="{x:Bind ThumbImage}" Width="150" HorizontalAlignment="Center" /> 
      <TextBlock FontSize="16" Text="{x:Bind Title}" HorizontalAlignment="Center" /> 
      <TextBlock FontSize="12" Text="{x:Bind Author}" HorizontalAlignment="Center" /> 
     </StackPanel> 
    </DataTemplate> 
</Page.Resources> 
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="100" /> 
    </Grid.RowDefinitions> 
    <GridView ItemsSource="{x:Bind Songs}" Grid.Row="0" Name="grid1" ItemTemplate="{StaticResource SongItemTemplate}" > 

    </GridView> 
</Grid>