创建绑定列表的新实例
时,我的Windows Phone应用程序崩溃BindedList更改:
OsyId = Response.recordedBills.Count > 50 ? new List<RecordedBillDetailViewModel>(Response.recordedBills.Take(50)) : new List<RecordedBillDetailViewModel>(Response.recordedBills);
多功能:
<toolkit:LongListMultiSelector ItemsSource="{Binding OsyId}" x:FieldModifier="public" x:Name="longList" EnforceIsSelectionEnabled="{Binding EnforceSelectionEnable}" Margin="0,0,10,0" SelectionChanged="LongListMultiSelector_SelectionChanged" IsSelectionEnabledChanged="LongListMultiSelector_IsSelectionEnabledChanged" MaxHeight="600" Grid.Row="1" HorizontalContentAlignment="Stretch">
崩溃报告:
{System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData)
at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData)
at MS.Internal.XcpImports.UIElement_TransformToVisual(UIElement element, UIElement visual)
at System.Windows.UIElement.TransformToVisual(UIElement visual)
at Microsoft.Phone.Controls.LongListMultiSelector.ApplyItemsState(State state, Boolean useTransitions)
at Microsoft.Phone.Controls.LongListMultiSelector.OnIsSelectionEnabledChanged(DependencyPropertyChangedEventArgs e)
at Microsoft.Phone.Controls.LongListMultiSelector.OnIsSelectionEnabledPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Microsoft.Phone.Controls.LongListMultiSelector.set_IsSelectionEnabled(Boolean value)
at Microsoft.Phone.Controls.LongListMultiSelector.UpdateIsSelectionEnabled()
at Microsoft.Phone.Controls.LongListMultiSelector.OnSelectionChanged(IList removedItems, IList addedItems)
at Microsoft.Phone.Controls.LongListMultiSelector.OnSelectedItemsCollectionCleared(Object sender, ClearedChangedArgs e)
at Microsoft.Phone.Controls.LongListMultiSelector.SelectedItemsList.ClearItems()
at System.Collections.ObjectModel.Collection1.Clear()
at Microsoft.Phone.Controls.LongListMultiSelector.OnItemsSourceChanged(Object oldValue, Object newValue)
at Microsoft.Phone.Controls.LongListMultiSelector.OnItemsSourcePropertyChanged(Object sender, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
at System.Windows.PropertyPathListener.RaisePropertyPathStepChanged(PropertyPathStep source)
at System.Windows.PropertyAccessPathStep.RaisePropertyPathStepChanged(PropertyListener source)
at System.Windows.CLRPropertyListener.SourcePropertyChanged(Object sender, PropertyChangedEventArgs args)
at System.Windows.Data.WeakPropertyChangedListener.PropertyChangedCallback(Object sender, PropertyChangedEventArgs args)
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
at Windows8.Common.Helpers.NotifyPropertyChanged.OnPropertyChanged(String propertyName)
at Windows8.Common.Helpers.NotifyPropertyChanged.SetProperty[T](T& storage, T value, String propertyName)
at Windows8.Common.ViewModels.BillPaymentViewModel.set_OsyId(List`1 value)
at Windows8.Common.ViewModels.BillPaymentViewModel.<InitiateBillRequestToRecordedBill>d__ee.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Windows8.Common.ViewModels.BillPaymentViewModel.<SetRecordedBillsAction>d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Windows8.Common.ViewModels.CompanyMenu.<BillPaymentSubScreenAction>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Windows8.Common.Helpers.DelegateCommandAsync.<System.Windows.Input.ICommand.Execute>d__0.MoveNext()}
我该如何解决?
答案 0 :(得分:1)
尝试清除项目并将其添加到列表中,而不是创建新实例。它可能有助于解决问题。这假设OsyId
是ObservableCollection<RecordedBillDetailViewModel>
var itemsToAdd = Response.recordedBills.Take(50); // Take 50 is fine even when the response does not have 50 items. Need not add a contion for it.
OsyId.Clear();
foreach(var item in itemsToAdd)
OsyId.Add(item)
谢谢, Shubhan
答案 1 :(得分:0)
正如@Shubhan所说,它必须仅由ObservableCollection
绑定,因为它使用INotifyCollectionChanged
事件。列表正在使用IPropertyChangedEvent
。 LongListSelector
中有一个类似的事件:
xxxxx as INotifyCollectionChange;
它正在使用xxxx
事件来重新绑定或调整事务大小。
感谢。