XAML如何在一列中显示gridview?

时间:2016-05-23 04:53:30

标签: c# xaml gridview

这是我的XAML代码

<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

我需要在列中创建项目,例如listview。默认情况下,gridview项目显示在表格中,我需要一个列表。感谢。

1 个答案:

答案 0 :(得分:-1)

我认为它是这样显示的,因为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>