【问题标题】:XAML how to show gridview in one column?XAML如何在一列中显示gridview?
【发布时间】:2016-05-23 04:53:30
【问题描述】:

这是我的 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>

我需要在一列中制作项目,例如列表视图。默认情况下,gridview 中的项目显示类似于表格,我需要一个列表。谢谢。

【问题讨论】:

  • 那你为什么不直接使用 ListView 呢?
  • @Bart 谢谢,效果很好。如何用堆栈面板填充所有列表视图?使宽度达到 100%?

标签: c# xaml gridview


【解决方案1】:

我认为它之所以这样显示是因为 gridview 需要分配给某些 Row?将 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>

【讨论】:

    猜你喜欢
    • 2012-12-28
    • 1970-01-01
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多