我有一个长列表选择器,其中我显示按日期排序的数据。
我面临的问题是列表第一次成功加载,但在返回到详细页面中包含longlistselctor的页面后,应用程序崩溃,出现以下异常:
System.NullReferenceException was unhandled
Message=NullReferenceException
StackTrace:
at Microsoft.Phone.Controls.LongListSelector.Balance()
at Microsoft.Phone.Controls.LongListSelector.LongListSelector_LayoutUpdated(Object sender, EventArgs e)
at System.Windows.FrameworkElement.OnLayoutUpdated(Object sender, EventArgs e)
at MS.Internal.JoltHelper.RaiseEvent(IntPtr target, UInt32 eventId, IntPtr coreEventArgs, UInt32 eventArgsTypeIndex)
由于发生了什么,我甚至无法追查。 该列表填充为:
currentAudioList = DiaryDBController.DBController.GetDiaryRecordsWithAudio();
var DiaryAudioRecordsByDate = from rec in currentAudioList
group rec by rec.CreationDate into r
orderby r.Key
select new Group<DatabaseClasses.DiaryRecord>(r.Key, r);
try
{
this.AudioGroupListSelector.ItemsSource = DiaryAudioRecordsByDate;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
var DiaryAudioRecordsByDate = from rec in currentAudioList
group rec by rec.CreationDate into r
orderby r.Key
select new Group<DatabaseClasses.DiaryRecord>(r.Key, r);
try
{
this.AudioGroupListSelector.ItemsSource = DiaryAudioRecordsByDate;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
}
任何帮助将不胜感激。 感谢。
答案 0 :(得分:2)
我遇到了同样的问题,在Codeplex上报告here以及可能的解决方法。
看起来可以通过更改LongListSelector.Balance()方法的第一行来解决问题:
if( !IsReady() || _flattenedItems.Count == 0 )
到
if( !IsReady() || _flattenedItems == null || _flattenedItems.Count == 0 )