YosiFZ
YosiFZ

Reputation: 7900

LongListSelector SelectionChanged won't called

I have this Template in LongListSelector:

<local:SearchTemplateSelector.LoadMoreTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <TextBlock Text="Load more..." FontSize="30" Foreground="White" TextWrapping="Wrap" Grid.Row="0" 
                                               HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,35"/>
                                    <Rectangle Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Fill="White" Grid.Row="1" Opacity="0.3"/>
                                </Grid>
                            </DataTemplate>
                        </local:SearchTemplateSelector.LoadMoreTemplate>

This is the LongListSelector:

    <Controls:LongListSelector x:Name="searchList" Margin="0,0,0,0"  Background="Black" SelectionChanged="DidPressSelectSearchList" 
                               HorizontalContentAlignment="Stretch" KeyDown="UserPressEnterKeyBoard" Grid.Row="1">
        <Controls:LongListSelector.ItemTemplate>
            <DataTemplate>
                <local:SearchTemplateSelector Content="{Binding}" HorizontalContentAlignment="Stretch">

And i have a problem that when i press this row in the list so the DidPressSelectSearchList called only when i press the TextBlock and not trigger if i press another place on the Row.

Any idea how to fix it?

Edit i try this:

<local:SearchTemplateSelector Content="{Binding}" HorizontalContentAlignment="Stretch" Background="Transparent">

And it still won't work.

Upvotes: 0

Views: 340

Answers (2)

Maks
Maks

Reputation: 2955

I had the problem like yours (LongListSelector error).

I tried to figure out how to solve it, but I didn't find the solution. I added the picture to describe the problem more clearly. The blue box (on the picture) is the area when tap event raise, the red box is the area when nothing happen, when you tapped there. When I use a Listbox instead of using a LongListSelector all works normally as expected.

But I tried that Silver Solver advised and it is really works for me. I think, you simple made a mistake.

Notice this property Background="Transparent" inside <Grid> element, which placed inside <DataTemplate> and <toolkit:LongListMultiSelector.ItemTemplate> consistently (code placed below).

I think you had the problem, because you should set <Grid> element for the <Controls:LongListSelector.ItemTemplate> and then set Background="Transparent" to the <Grid> element. Then you could put inside <Grid> element anything you like. Also you can add event Tap="Grid_Tap"for the <Grid> element, so it will triggered whenever you tap inside <Grid> element area.

This is my sample of code, try it:

<toolkit:LongListMultiSelector                    
                x:Name="LongListMultiSelector" 
                Margin="0,0,0,0"  
                ItemsSource="{Binding}"                     
                SelectionChanged="SelectionChanged"
                IsSelectionEnabledChanged="IsSelectionEnabledChanged"                              
                EnforceIsSelectionEnabled="False" 
                >
                <toolkit:LongListMultiSelector.ItemTemplate>
                    <DataTemplate>                            
                        <Grid Margin="0,0,0,17" 
                              Tap="Grid_Tap"                                       
                              HorizontalAlignment="Stretch" 
                              VerticalAlignment="Stretch"  
                              Background="Transparent">                                     
                            <TextBlock  Text="{Binding Text}"
                                        TextWrapping="NoWrap"
                                        Style="{StaticResource PhoneTextLargeStyle}"                                            
                                        HorizontalAlignment="Left"                                          
                                        />                                        
                        </Grid>                            
                    </DataTemplate> 
                </toolkit:LongListMultiSelector.ItemTemplate>    

P.S. Silver Solver thank you very much, sorry but I can't increase you reputation due to the small reputation.

Upvotes: 1

Silver Solver
Silver Solver

Reputation: 2320

Make sure that your root element in the ItemTemplate has a background set, else it will not register clicks.

<DataTemplate>
            <local:SearchTemplateSelector Background="Transparent"...

If your Selector does not have a Background property, just wrap it in a Grid.

Upvotes: 0

Related Questions