Question

I have longlist selector, in page load assigning the data as ItemSource. like below,

objectType = "mobilecontacts";
Contacts = (List<AllMobileContacts>)PhoneApplicationService.Current.State["Contacts"];

Deployment.Current.Dispatcher.BeginInvoke(() =>
{
    peopleLongListSelector.Visibility = Visibility.Visible;
    chatpeopleLongListSelector.Visibility = Visibility.Collapsed;
    peopleLongListSelector.ItemsSource= Contacts;
});

And in textbox text changed event,

private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)
{
    progressBar.IsIndeterminate = true;
    TextBox tb = (TextBox)sender;
    string s = tb.Text;
    if (Contacts != null)
    {
        var searchName = 
                 (from name in Contacts
                       where name.USER_NAME.ToLower().Contains(s.ToLower())
                             select name).ToList();

        this.peopleLongListSelector.ItemsSource = null;
        this.peopleLongListSelector.ItemsSource = searchName;
    }
    else if (ChatContacts != null)
    {
        var searchName = 
                (from name in ChatContacts
                      where name.USERNAME.ToLower().Contains(s.ToLower())
                            select name).ToList();
        this.chatpeopleLongListSelector.ItemsSource = searchName;
    }
    progressBar.IsIndeterminate = false;
}

Everything is working fine, but while changing text 2-3 times it shows OutOfMemory exception.
Because that list has images and bunch of text.
How can I solve this issue..

Here is my Longlist Selector with DataTemplate:

<phone:LongListSelector Name="chatpeopleLongListSelector" Visibility="Collapsed">
    <phone:LongListSelector.ItemTemplate>
        <DataTemplate>
            <StackPanel x:Name="stackpanel" Orientation="Horizontal" Margin="10,0" 
                        Height="75" Width="450" Tap="ucSearch_Tap">
                <StackPanel Width="392" Orientation="Horizontal" HorizontalAlignment="Left">
                    <StackPanel Width="62">
                        <Image Height="62" Width="62" VerticalAlignment="Top" Name="profileimg"
                               Source="{Binding PROFILEPIC,Converter={StaticResource imageConverter}}" />
                    </StackPanel>
                    <StackPanel x:Name="stpUserName" Width="330" Orientation="Vertical">
                        <TextBlock x:Name="txtbUserName" Text="{Binding USERNAME}" 
                                   Style="{StaticResource PhoneTextLargeStyle}" FontSize="28"
                                   Foreground="#FF6B6D70" 
                                   FontFamily="/Assets/Fonts/ProximaNova-Light_0.otf#Proxima Nova" 
                                   VerticalAlignment="Center" HorizontalAlignment="Left" />
                        <TextBlock x:Name="txtNumber" Opacity="0.7" Text="{Binding From}" 
                                   Style="{StaticResource PhoneTextLargeStyle}" 
                                   Foreground="#FF6B6D70"
                                   FontFamily="/Assets/Fonts/ProximaNova-Light_0.otf#Proxima Nova" FontSize="16" 
                                   VerticalAlignment="Center" HorizontalAlignment="Left" />
                        <TextBlock x:Name="txChatType" Visibility="Collapsed" Opacity="0.7" 
                                   Text="{Binding IsChatType}" Foreground="#FF6B6D70"
                                   Style="{StaticResource PhoneTextLargeStyle}" 
                                   FontFamily="/Assets/Fonts/ProximaNova-Light_0.otf#Proxima Nova" 
                                   FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Left" />
                    </StackPanel>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
Was it helpful?

Solution

Simple I used ListBox control instead of LongListSelector, issue gone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top