如何在wp8中的LongListSelector中显示行号

时间:2014-01-22 06:10:00

标签: windows-phone-8

我想在文本块中显示行号,例如1,2,3 .....等等,具体取决于项目索引值

as like 
1.    value  value
2.
3.


 <phone:LongListSelector x:Name="MainLongListSelector" Margin="0,0,-12,0"
 ItemsSource="{Binding TaskList}" SelectionChanged="MainLongListSelector_SelectionChanged"
 Foreground="Black" Height="654" VerticalAlignment="Bottom">
         ....
 <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" Text="{ 1}" />

我该怎么做

  <phone:LongListSelector x:Name="MainLongListSelector" Margin="0,0,-12,0" ItemsSource="{Binding TaskList}" SelectionChanged="MainLongListSelector_SelectionChanged" Foreground="Black" Height="654" VerticalAlignment="Bottom">
            <phone:LongListSelector.ItemTemplate>
                <DataTemplate>
                    <Border Style="{StaticResource bordercss}" >
                        <Grid >
                            <Grid.Background>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="White" Offset="1"/>
                                    <GradientStop Color="Black" Offset="1"/>
                                </LinearGradientBrush>
                            </Grid.Background>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="5*"/>
                                <ColumnDefinition Width="5*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                                <RowDefinition></RowDefinition>
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" Text="{Binding }" />
                            <TextBlock  Grid.Row="0" Grid.Column="1" Text="{Binding title}" Style="{StaticResource textbold}" />
                            <Image  HorizontalAlignment="Right" Grid.Row="0" Grid.Column="2"  Source="/Assets/priority_low.png" Margin="5" Height="25" />

                            <Image HorizontalAlignment="Left"   Grid.Row="1" Grid.Column="0"  Source="/Assets/client_icon.png" Margin="5,5,0,5" Width="23"/>
                            <TextBlock  Grid.Row="1" Grid.Column="1" Text="{Binding clientname}" Style="{StaticResource textsimple}"  />

                            <Image  HorizontalAlignment="Left" Grid.Row="2" Grid.Column="0"  Source="/Assets/contact_icon.png" Margin="5,5,0,5" Width="17"/>
                            <TextBlock  Grid.Row="2" Grid.Column="1" Text="{Binding customercontact}" Style="{StaticResource textsimple}"   />

                            <Image HorizontalAlignment="Left" Grid.Row="3" Grid.Column="0"  Source="/Assets/address_icon.png" Margin="5,5,0,5" Width="20"/>
                            <TextBlock  Grid.Row="3" Grid.Column="1" Text="{Binding address}" Style="{StaticResource textsimple}"   />

                            <Button Grid.Row="4" Grid.ColumnSpan="2" VerticalAlignment="Center"  HorizontalAlignment="left" Grid.Column="0" Content="{Binding expdate}" Margin="-12,0,-12,-12" Background="#FFD6D6D6" Foreground="Black" Height="80"  />

                            <Button Grid.Row="4" Grid.Column="2" Content="Status" Margin="-10,0,-12,-12" Background="#FFD6D6D6" Foreground="Black" Padding="0,0,5,0" Height="80"  />

                        </Grid>

                    </Border>

                </DataTemplate>
            </phone:LongListSelector.ItemTemplate>
        </phone:LongListSelector>

1 个答案:

答案 0 :(得分:1)

不是最好的解决方案但是可以在某些方面帮助你。

在TaskList类型类定义

只需添加

等成员即可
public class YourClass
{
public int BindingId{get;set;}
}

现在在TaskList被填满的地方

制作一个像这样的循环

for (int i = 0; i < TaskList.Count; i++)
{
TaskList[i].BindingId= i;
}

完成循环后,您将获得一个附加列表中每个项目的自动增量编号。只需使用它进行绑定。