Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight a selected item in the LongListSelector on WP8?

How is it possible to highlight the selected item in the new LongListSelector on Windows Phone 8? Actually nothing happend if I tapped one entry of the list. My list only contains a simple string which will be displayed through a TextBlock. But I want to highlight the selection of the user.

Thanks.

like image 205
Thomas Sebastian Jensen Avatar asked Dec 14 '12 07:12

Thomas Sebastian Jensen


1 Answers

In my case I used a RadioButtonControl in the DataTemplate of the LongListSelectorItem to achieve this. You will have a checked oder unchecked sign at the left border.

In any case it is important, that you set the same group for all Radiobuttons, so the selection only represents one entry.

Inside the Contentor your RadioButton you can put the TextBlock bound to the String.

Im currently not at home, but if this wont solve your problem, I'll provide you some code when I'm at home ;)

Here you go:

<LongListSelector.ItemTemplate>
    <DataTemplate>
        <ContentControl HorizontalAlignment="Stretch" HorizontalContentAlignment="Left">
            <RadioButton HorizontalAlignment="Stretch" Margin="0,0,0,0" GroupName="A" Background="Black" >
                <StackPanel toolkit:TiltEffect.IsTiltEnabled="True">
                    <TextBlock Text="{Binding Path=XXX}" 
                               TextWrapping="Wrap"
                               Foreground="Black" 
                               Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                    <TextBlock Text="{Binding Path=XXXX}" 
                               TextWrapping="Wrap" 
                               Foreground="Black" 
                               Margin="14,-6,0,0" 
                               Style="{StaticResource PhoneTextSubtleStyle}"/>
                </StackPanel>
            </RadioButton>
        </ContentControl>
    </DataTemplate>
</LongListSelector.ItemTemplate>
like image 174
Johannes Wanzek Avatar answered Nov 03 '22 00:11

Johannes Wanzek