tags:

views:

107

answers:

1

Assume that the below XAML is a style applied to a Path that is a visual element of an item data template for a collection, I want to bind to the collection in such a way that if this is the first element of a collection, the path is collapsed. How can I go about doing this?

<Style x:Key="PathStyle" TargetType="{x:Type Path}">
   <Style.Triggers>
      <DataTrigger Value="0" Binding="{Binding Index}">
         <Setter Property="Visibility" Value="Collapsed"/>
      </DataTrigger>
   </Style.Triggers>
</Style>
+1  A: 

For the sake of readability, I'd use a view model, but you should also be able to use a RelativeSource in PreviousData mode:

<DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
    <Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>

When there is no previous data item (ie. first item in the collection), PreviousData will return null.

HTH, Kent

Kent Boogaart