Winrt - ListView 最后一项的特定 ItemTemplate

Winrt - Specific ItemTemplate on last item of ListView

我在 windows 商店应用程序项目中有此列表视图

<ListView ItemsSource="{Binding Attachments}"  IsItemClickEnabled="False" SelectionMode="None">
                                <ListView.ItemTemplate>
                                    <DataTemplate >
                                        <Grid Width="280" Height="50" Margin="85,0,0,0">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="*"/>
                                                <RowDefinition Height="5" />
                                            </Grid.RowDefinitions>
                                            <RadioButton GroupName="meetingFiles" Content="TESTE" Style="{StaticResource RadioButtonStyle1}"></RadioButton>
                                            <TextBlock Text="1" HorizontalAlignment="Right"></TextBlock>
                                            <Grid x:Name="whiteLine" Grid.Row="1" Width="270" Height="1" Background="White" HorizontalAlignment="Center" />
                                        </Grid>
                                    </DataTemplate>
                                </ListView.ItemTemplate>
                            </ListView>

我希望列表视图中的最后一项不显示名为 whiteLine 的网格 我怎样才能做到这一点?还是不可能?

两者都

<ListView ItemTemplateSelector="..."/> 

或者绑定 Grid's Visibility 就可以了。但是您的模型中需要某种类型的标志变量,以便您可以使用它来确定它是否是列表中的最后一个。

我使用上述解决方案来交替 ListView 中每个项目的背景颜色,我的模型也包含一个 RowID。

另一种解决方案是这样添加 Listview.footer

<ListView>
     <!-- Your Listview ItemTemplate /-->
     <ListView.Footer>
           <Grid Width="280" Height="50" Margin="85,0,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="5" />
           </Grid.RowDefinitions>
           <RadioButton GroupName="meetingFiles" Content="TESTE" Style="{StaticResource RadioButtonStyle1}"></RadioButton>
           <TextBlock Text="1" HorizontalAlignment="Right"></TextBlock>
     </ListView.Footer>
</ListView>

这并没有真正改变最后一个项目,它添加了一个始终位于 ListView 底部且看起来与您的项目相同的元素。这会给用户一种印象,它是列表视图的一部分,并且您将保持代码简单。