Item index of Binding element

Posted by vibeeshanRC on Stack Overflow See other posts from Stack Overflow or by vibeeshanRC
Published on 2012-11-17T16:45:23Z Indexed on 2012/11/17 17:00 UTC
Read the original article Hit count: 215

I am creating a XAML / C# WinRT App and i have a collection of collection and i am binding it to a Grid-view(collections as groups )

Now i have to color the background of the GridViewItem according to their index in the collection (Dark color for the first one and light color for the last one ) How can i implement using a converter. (if there are 6 collections with 10 items all the first item will the dark and the 10 the item will be lighter).

Simply: How can i send the item-index property to the converter as a parameter.

My XAML

<GridView x:Name="Grid1" ItemsSource="{Binding}"
                  ItemTemplateSelector="{StaticResource templateSelector}"                       
                  SelectionMode="None"   >               

            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel  Orientation="Horizontal" VirtualizingStackPanel.VirtualizationMode="Recycling"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>

            <GridView.GroupStyle>

                <GroupStyle HidesIfEmpty="True">
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid  Margin="0,0,0,0">
                                <TextBlock Text='{Binding Name}' 
                                  Margin="5" />
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>

                    <GroupStyle.ContainerStyle>
                        <Style TargetType="GroupItem" >

                            <Setter Property="BorderThickness" Value="0"/>
                            <Setter Property="Margin" Value="0,0"/>
                        </Style>
                    </GroupStyle.ContainerStyle>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid/>
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </GridView.GroupStyle>
        </GridView>

..........

   <converters:MyConverter x:Key="templateSelector"
                           Temp1="{StaticResource Temp1}"
                           Temp2="{StaticResource Temp2}"
                           >
    </converters:MyConverter> 

 <DataTemplate x:Key="Temp1">
  <Grid >
    <Grid>
       <Grid.Resources>
         <converters:PanelBackgroundColorConverter x:Name="panelBackgroundColorConverter" Key="{Binding}"/>
         <Grid.Resources/>
        <Grid.Background>
                    <Binding Path="MPath" Converter="{StaticResource panelBackgroundColorConverter}" ConverterParameter="sym"/>
         </Grid.Background>               
        <Grid/>
 <DataTemplate/>

© Stack Overflow or respective owner

Related posts about c#

Related posts about xaml