Q:

Line separator in DataTemplate for ListView

I have ItemsControl with bindable itemsource and custom datetemplate for each item. Items are separated by line. But last item has separator too, and that's my problem, how to not render line for last item. I've found this solution, but it's working in WPF:
How can a separator be added between items in an ItemsControl
EDIT:
Here is my template:
<ItemsControl Grid.Row="1"  ItemsSource="{x:Bind ViewModel.AvailableStatuses}" x:Name="Statuses">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" Padding="60,0,60,12"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid Background="Transparent">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <i:Interaction.Behaviors>
                                    <core:EventTriggerBehavior EventName="Tapped">
                                        <core:InvokeCommandAction Command="{Binding ElementName=ContentGrid, Path=DataContext.ChangeStatusCommand}" CommandParameter="{Binding}"/>
                                    </core:EventTriggerBehavior>
                                </i:Interaction.Behaviors>
                                <Rectangle StrokeThickness="0.4" Height="0.4" x:Name="Separator" 
                                   VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Stroke="#D1D3D4" />
                                <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Stretch">
                                    <Image Source="{Binding Converter={StaticResource SelectContactStatusConverter}}" Margin="0,8,12,8"/>
                                    <TextBlock Text="{Binding Converter={StaticResource EnumContactStatusToTextConverter}}" FontSize="20" VerticalAlignment="Center" Foreground="Black"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

A:

There's probably a few different ways of doing this, here's my take.
Style your ListView's item containers with the border brush and thickness you want to have, and subscribe to the ContainerContentChanging event:
<ListView ContainerContentChanging="ListView_ContainerContentChanging">
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="0,1,0,0"/>
        </Style>
    </ListView.ItemContainerStyle>

    <x:String>1</x:String>
    <x:String>2</x:String>
    <x:String>3</x:String>
    <x:String>4</x:String>
</ListView>

In your code behind:
private void ListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
    if (args.InRecycleQueue)
    {
        // Item is being recycled, make sure first item has no border
        if (args.ItemIndex == 0)
        {
            var first = (ListViewItem)sender.ContainerFromIndex(0);
            if (first != null)
            {
                first.BorderThickness = new Thickness(0);
            }
        }
    }
    else if (args.ItemIndex == 0)
    {
        // A new first item
        ((ListViewItem)args.ItemContainer).BorderThickness = new Thickness(0);

        var second = (ListViewItem)sender.ContainerFromIndex(1);
        if (second != null)
        {
            second.ClearValue(BorderThicknessProperty);
        }
    }
    else
    {
        // A new internal item
        ((ListViewItem)args.ItemContainer).ClearValue(BorderThicknessProperty);
    }
}

I decided on this approach for a few reasons:

It makes sense to apply the border style to the ListViewItem instead of within the ItemTemplate because it will be the same for all items in the list regardless of which item template is used for a particular item. Also, it will ensure that the line touches the very left and right edge of the ListView.
The visual appearance of the separators can be adjusted in XAML. The code-behind can be put into a behavior (or subclass the ListView) if you want to reuse it.
It will maintain the correct appearance even when items are added/removed from the list, or when items are reordered.
It works correctly with UI virtualization.
It is independent of the data bound to the list view.

EDIT
It looks like you meant for an ItemsControl, not a ListView. If that's the case, then you'd have to do something along Depechie's answer because ItemsControl doesn't have the ContainerContentChanging event (subclass ItemsControl and override PrepareContainerForItemOverride instead), but this likely won't work for dynamic lists with items added and removed at runtime. You'd have to experiment with different solutions if this is important to you.

