i have a long list selector in which i’m displaying data sorted by date.
The problem i’m facing is that the list loads successfully for the first time, but after coming back to the page containg the longlistselctor from the details page, the app is crashing with the following exception:
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)
I’m not even able to trace because of what this is happening.
The list is populated as:
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);
}
Any help will be appreciated.
Thanks.
I’ve had the same issue, it is reported here on Codeplex along with a possible workaround.
It looks like the problem can be fixed by changing the first line of the LongListSelector.Balance() method from:
to