0
votes

I have longlistselector with two textblocks.The second textblock is populated with some items. The problem is that i can't add some string before every item.In particular I want to add A-Z order before every item.Here is my XAML code for the LongListSelector:

<phone:LongListSelector 
              Name="llsPrasanje"
              Grid.Row="1" 
              ItemsSource="{Binding Items}" 
              Margin="12,12,12,12">
                 <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>              
                       <Grid>
                          <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                           </Grid.ColumnDefinitions>
                       <TextBlock Name="txtBukva" Text=""/>
                       <TextBlock Text="{Binding Odgovor}" Grid.Column="1"/>
                            </Grid>
                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>

For example I want to show the items like this:

A: firstItem       
B: secondItem
C: thirdItem

firstItem,secondItem,thirdItem get the values from the {Binding Odgovor}. I want the first TextBlock to generate A,B,C... before every item. How can i accomplish this?

1
what happens if there are more items then letters in the alphabet?sa_ddam213
The property generates maximum 4 items so that will never happenMr D-Code

1 Answers

0
votes
<TextBlock Name="txtBukva" Text="{Binding Index}"/>

class X
{
    public string Index { get; set; }
    public string Odgovor { get; set; }
}

class MyViewModel
{
    private List<X> _items;
    public List<X> Items
    {
        get
        {
            return _items;
        }
        set
        {
            Debug.Assert(_items.Count <= 26);
            _items = value;
            for(int i = 0; i < _items.Count; i++)
            {
                _items[i].Index = ('A' + i) + "";
            }
        }
    }
}