Search code examples
c#xamlwindows-runtimewindows-store-appswinrt-xaml

Winrt - Specific ItemTemplate on last item of ListView


I have this list view on a windows store app project

<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>

i want that my last item on the listview dont show the grid named whiteLine how can i do that? or is it impossible?


Solution

  • Either

    <ListView ItemTemplateSelector="..."/> 
    

    Or binding the Grid's Visibility would do the trick. But you would need some type of flag variable in your Model such that you can use that to determine if it is the last one in the list.

    I used the above solution to alternate the background color of each item in the ListView, with my Model containing a RowID as well.