2

I should separate ListViewItem of ListView. I wrote next XAML for it:

<Window.Resources>
    <Style x:Key="myTemplate" TargetType="ListViewItem">
        <Setter Property="BorderThickness" Value="0,4,0,0"/>
        <Setter Property="BorderBrush" Value="Red"/>
    </Style>


</Window.Resources>

Now I can use this resources by the next way:

<Grid>
        <ListView Name="listview1" HorizontalAlignment="Left" Height="164" Margin="191,83,0,0" VerticalAlignment="Top" Width="307" ItemContainerStyle="{StaticResource myTemplate}" BorderThickness="5">

            <ListView.View>
                <GridView>
                    <GridViewColumn>
                    </GridViewColumn>
                </GridView>
            </ListView.View>

            <!--this data is only for sample. Really it's load by binding-->
                <ListViewItem Content="1"/>

                <ListViewItem Content="2"/>

                <ListViewItem Content="3"/>
        </ListView>

Yes, everythink works fine but I don't want to apply this style for first element (I don't want to see border for first element). If I use next way for realize required view, items don't highlighted when it's selected:

<Window.Resources>
    <Style x:Key="myTemplate" TargetType="ListViewItem">                        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <StackPanel>
                        <Separator x:Name="Separator"/>
                        <ContentPresenter/>
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                            <Setter Property="Visibility" TargetName="Separator" Value="Collapsed"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


</Window.Resources>

How to realize required view?

Mixim
  • 972
  • 1
  • 11
  • 37
  • Check [this question on SO](http://stackoverflow.com/questions/2511227/how-can-a-separator-be-added-between-items-in-an-itemscontrol) – gehho Mar 19 '14 at 14:34

1 Answers1

0

Just create two styles, the first style (without separator) is applied only on the first element, and the second style ((with separator) one is applied to all the remaining elements.

NTinkicht
  • 972
  • 2
  • 12
  • 34