我有longlist选择器,在页面加载中将数据分配为ItemSource。 如下,
objectType = "mobilecontacts";
Contacts = (List<AllMobileContacts>)PhoneApplicationService.Current.State["Contacts"];
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
peopleLongListSelector.Visibility = Visibility.Visible;
chatpeopleLongListSelector.Visibility = Visibility.Collapsed;
peopleLongListSelector.ItemsSource= Contacts;
});
在文本框文本中更改了事件,
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;
}
一切正常,但在改变文字2-3次时会显示OutOfMemory异常 因为该列表包含图像和一堆文本 我该如何解决这个问题..
这是我的带有DataTemplate的Longlist选择器:
<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>
答案 0 :(得分:0)
简单我使用了ListBox控件而不是LongListSelector,问题就消失了。