2015-09-10 3 views
2

Исключение XamlParse в приложении WP8.1, созданное с использованием VS2013 при использовании LongListSelector с привязкой данных к ObservableCollection.Удалить элементы из ObservableCollection throws System.Windows.Markup.XamlParseException: [Line: 0 Position: 0]

Все в порядке, пока не удалите элемент из коллекции. Странно, что исключение генерируется только в том случае, если Canvas находится на Grid.Row = «1».

Если canvas находится на Grid.Row = "0" все в порядке.

Я сделал простой пример только с двумя связями данных.


Исключение

 

A first chance exception of type 'System.ArgumentException' occurred in System.Windows.ni.dll 
Additional information: Value does not fall within the expected range. 


-  e {System.Windows.ApplicationUnhandledExceptionEventArgs} System.Windows.ApplicationUnhandledExceptionEventArgs 
+  base {System.Windows.ApplicationUnhandledExceptionEventArgs} System.EventArgs {System.Windows.ApplicationUnhandledExceptionEventArgs} 
-  ExceptionObject {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight) 
    --- End of inner exception stack trace ---} System.Exception {System.Windows.Markup.XamlParseException} 
-  [System.Windows.Markup.XamlParseException] {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight) 
    --- End of inner exception stack trace ---} System.Windows.Markup.XamlParseException 
+  base {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight) 
    --- End of inner exception stack trace ---} System.SystemException {System.Windows.Markup.XamlParseException} 
     LineNumber 0 int 
     LinePosition 0 int 
-  Non-Public members  
+  base {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight) 
    --- End of inner exception stack trace ---} System.SystemException {System.Windows.Markup.XamlParseException} 
     _errorCode 2148468948 uint 
     _lineNumber 0 int 
     _linePosition 0 int 
     ErrorCode 2148468948 uint 
-  Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} 
+  [System.Collections.ListDictionaryInternal] {System.Collections.ListDictionaryInternal} System.Collections.ListDictionaryInternal 
     IsFixedSize false bool 
     IsReadOnly false bool 
+  Keys {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} 
+  Values {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} 
     HelpLink null string 
     HResult -2146233087 int 
-  InnerException {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)} System.Exception {System.Windows.Markup.XamlParseException} 
+  [System.Windows.Markup.XamlParseException] {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)} System.Windows.Markup.XamlParseException 
-  Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} 
+  [System.Collections.ListDictionaryInternal] {System.Collections.ListDictionaryInternal} System.Collections.ListDictionaryInternal 
     IsFixedSize false bool 
     IsReadOnly false bool 
+  Keys {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} 
+  Values {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} 
     HelpLink null string 
     HResult -2146233087 int 
+  InnerException null System.Exception 
     Message " [Line: 0 Position: 0]" string 
     Source "System.Windows" string 
     StackTrace " at MS.Internal.XcpImports.CheckHResult(UInt32 hr)\r\n at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)\r\n at System.Windows.UIElement.Measure(Size availableSize)\r\n at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options)\r\n at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom)\r\n at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom)\r\n at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated)\r\n at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport)\r\n at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize)\r\n at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)" string 
+  Static members  
+  Non-Public members  
     Message " [Line: 0 Position: 0]" string 
     Source null string 
     StackTrace null string 
+  Static members  
-  Non-Public members  
+  [System.Windows.Markup.XamlParseException] {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] ---> System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight) 
    --- End of inner exception stack trace ---} System.Windows.Markup.XamlParseException 
     _className "System.Windows.Markup.XamlParseException" string 
+  _data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} 
     _dynamicMethods null object 
     _exceptionMethod null System.Reflection.MethodBase 
     _exceptionMethodString null string 
     _helpURL null string 
     _HResult -2146233087 int 
+  _innerException {System.Windows.Markup.XamlParseException: [Line: 0 Position: 0] 
    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight)} System.Exception {System.Windows.Markup.XamlParseException} 
+  _ipForWatsonBuckets 0 System.UIntPtr 
     _message " [Line: 0 Position: 0]" string 
     _remoteStackIndex 0 int 
     _remoteStackTraceString null string 
     _source null string 
     _stackTrace null object 
     _stackTraceString null string 
     _watsonBuckets null object 
     _xcode -532462766 int 
+  _xptrs 0 System.IntPtr 
+  IPForWatsonBuckets 0 System.UIntPtr 
     IsTransient false bool 
     RemoteStackTrace null string 
     WatsonBuckets null object 
     Handled false bool 
+  Non-Public members  

    at MS.Internal.XcpImports.CheckHResult(UInt32 hr) 
    at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize) 
    at System.Windows.UIElement.Measure(Size availableSize) 
    at Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Iterator`1 iterator, RealizeOptions options) 
    at Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.AppendElement(RealizedRange range, RealizedRange nextRange, Double bottom) 
    at Microsoft.Phone.Controls.LongListSelector.HealElements(Rect requireRect, Rect allowRect, Boolean& areBoundsUpdated) 
    at Microsoft.Phone.Controls.LongListSelector.Balance(Boolean containerViewport) 
    at Microsoft.Phone.Controls.LongListSelector.MeasureOverride(Size availableSize) 
    at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Double inWidth, Double inHeight, Double& outWidth, Double& outHeight) 



> System.Windows.ni.dll!MS.Internal.XcpImports.CheckHResult(uint hr) Unknown 
    System.Windows.ni.dll!MS.Internal.XcpImports.SetValue(MS.Internal.IManagedPeerBase obj, System.Windows.DependencyProperty property, System.Windows.DependencyObject doh) Unknown 
    System.Windows.ni.dll!MS.Internal.XcpImports.SetValue(MS.Internal.IManagedPeerBase doh, System.Windows.DependencyProperty property, object obj) Unknown 
    System.Windows.ni.dll!System.Windows.DependencyObject.SetObjectValueToCore(System.Windows.DependencyProperty dp, object value) Unknown 
    System.Windows.ni.dll!System.Windows.DependencyObject.SetEffectiveValue(System.Windows.DependencyProperty property, ref System.Windows.EffectiveValueEntry newEntry, object newValue) Unknown 
    System.Windows.ni.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation) Unknown 
    System.Windows.ni.dll!System.Windows.DependencyObject.RefreshExpression(System.Windows.DependencyProperty dp) Unknown 
    System.Windows.ni.dll!System.Windows.Data.BindingExpression.SendDataToTarget() Unknown 
    System.Windows.ni.dll!System.Windows.Data.BindingExpression.SourceAcquired() Unknown 
    System.Windows.ni.dll!System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.Data.BindingExpression.DataContextChanged(object sender, System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.OnDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.OnAncestorDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.NotifyDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.OnAncestorDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.NotifyDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.OnAncestorDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.NotifyDataContextChanged(System.Windows.DataContextChangedEventArgs e) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyProperty dp) Unknown 
    System.Windows.ni.dll!System.Windows.DependencyObject.RaisePropertyChangeNotifications(System.Windows.DependencyProperty dp, object oldValue, object newValue) Unknown 
    System.Windows.ni.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.DependencyProperty property, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, System.Windows.DependencyObject.ValueOperation operation) Unknown 
    System.Windows.ni.dll!System.Windows.DependencyObject.SetValueInternal(System.Windows.DependencyProperty dp, object value, bool allowReadOnlySet) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.DataContext.set(object value) Unknown 
    [Native to Managed Transition] 
    System.Windows.ni.dll!MS.Internal.FrameworkCallbacks.SetPropertyOrAddItem(object target, System.Reflection.PropertyInfo propertyInfo, object value, int typeIndex, string propertyName) Unknown 
    System.Windows.ni.dll!MS.Internal.FrameworkCallbacks.SetNonAttachedProperty(object target, string propertyName, object propertyValue, int typeIndex) Unknown 
    System.Windows.ni.dll!MS.Internal.FrameworkCallbacks.SetValueToProperty(object target, string propertyName, object propertyValue, int typeIndex, string attachedDPOwnerNamespace, string attachedDPOwnerAssembly) Unknown 
    System.Windows.ni.dll!MS.Internal.FrameworkCallbacks.SetProperty(System.IntPtr nativeTarget, string propertyName, ref MS.Internal.CValue propertyValue, int typeIndex, string attachedDPOwnerNamespace, string attachedDPOwnerAssembly) Unknown 
    [Native to Managed Transition] 
    [Managed to Native Transition] 
    System.Windows.ni.dll!MS.Internal.XcpImports.UIElement_Measure(System.Windows.UIElement element, System.Windows.Size availableSize) Unknown 
    System.Windows.ni.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) Unknown 
    Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.LongListSelector.RealizeDisplayItem(Microsoft.Phone.Controls.Iterator iterator, Microsoft.Phone.Controls.LongListSelector.RealizeOptions options) Unknown 
    Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.LongListSelector.RealizedRange.Append(Microsoft.Phone.Controls.LongListSelector.RealizedRange nextRange, double bottom) Unknown 
    Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.LongListSelector.AppendElement(Microsoft.Phone.Controls.LongListSelector.RealizedRange range, Microsoft.Phone.Controls.LongListSelector.RealizedRange nextRange, double bottom) Unknown 
    Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.LongListSelector.HealElements(System.Windows.Rect requireRect, System.Windows.Rect allowRect, out bool areBoundsUpdated) Unknown 
    Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.LongListSelector.Balance(bool containerViewport) Unknown 
    Microsoft.Phone.ni.dll!Microsoft.Phone.Controls.LongListSelector.MeasureOverride(System.Windows.Size availableSize) Unknown 
    System.Windows.ni.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, double inWidth, double inHeight, out double outWidth, out double outHeight) Unknown 

Xaml Пример

<phone:PivotItem x:Name="PivotMyPage" Header="My Page" > 
<Grid x:Name="LayoutMyPage" Background="Transparent"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <phone:LongListSelector Name="LLS_MyItems" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding myItemCollection}" > 
     <phone:LongListSelector.ItemTemplate> 
      <DataTemplate x:Name="DataTemplateMyPage"> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto" /> 
         <RowDefinition Height="Auto" /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="Auto" /> 
         <ColumnDefinition Width="Auto" /> 
        </Grid.ColumnDefinitions> 
        <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Title}" HorizontalAlignment="Left" /> 
        <Canvas  Grid.Row="1" Grid.Column="1" Width="50" Height="50" HorizontalAlignment="Center" VerticalAlignment="Center" > 
         <Polyline Canvas.Left="0" Canvas.Top="0" Points="{Binding PC}" Stroke="Gray" StrokeThickness="4" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
        </Canvas> 
       </Grid> 
      </DataTemplate> 
     </phone:LongListSelector.ItemTemplate> 
    </phone:LongListSelector> 
</Grid> 

код Позади

bool mainPivotLoaded = false; 
    private ObservableCollection<MyItem> myItemCollection = new ObservableCollection<MyItem>(); 

    public MainPage() 
    { 
     InitializeComponent(); 
     DataContext = App.ViewModel; 
     LLS_MyItems.ItemsSource = myItemCollection; 

     for (int x = 0; x < 20; x++) 
     { 
      MyItem i = new MyItem(); 
      i.Title = "Hello" + x.ToString(); 
      myItemCollection.Add(i); 
     } 

     DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer(); 
     dt.Tick += new EventHandler(Dt_Tick); 
     dt.Interval = new TimeSpan(0, 0, 0, 1, 0); 
     dt.Start(); 
    } 

    private void Dt_Tick(object sender, EventArgs e) 
    { 
     if (myItemCollection.Count > 0 && mainPivotLoaded) 
      myItemCollection.RemoveAt(0); 
    } 
    private void MainPivot_Loaded(object sender, RoutedEventArgs e) 
    { 
     mainPivotLoaded = true; 
    } 



class MyItem : INotifyPropertyChanged 
{ 
    public string Title { get; set; } 
    public PointCollection PC { get; set; } 

    public event PropertyChangedEventHandler PropertyChanged; 
    public void NotifyPropertyChanged(String propertyName) 
    { 
     if (PropertyChanged != null) 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
    } 
    public MyItem() 
    { 
     PC = new PointCollection(); 
     PC.Add(new Point(1, 1)); 
     PC.Add(new Point(10, 10)); 
    } 
} 
+0

За исключением исключения, поэтому он должен работать. Или, [edit] и вставьте текст исключения в свой вопрос. – Will

+0

См. Внутреннее исключение выше В System.Windows.ni.dll произошла первая случайная ошибка типа «System.ArgumentException». Дополнительная информация: Значение не входит в ожидаемый диапазон. – user3131108

+0

Все детали исключения. Не меньше. – Will

ответ

0

Это связывание осмотрителен

Points="{Binding PC}" 

Что должно произойти, когда

  1. PC является недействительным?
  2. Не удалось найти привязку к ПК?
  3. ПК не имеет нуля, но нет элементов?
  4. PC имеет элементы

я предполагаю код ручки # 4, но не обрабатывает 1 - 3. При кодировании для всех ситуаций с действительным списком по крайней мере, было бы разумно.

+0

Я мой пример ПК никогда не был нулевым. Но я не знаю, что произойдет, если я удалю элемент из коллекции. Является ли привязка еще ссылкой на уничтоженный элемент? Я попытался установить TargetNullValue без успеха (Points = "{Binding PC, TargetNullValue = '0,0'}"). BTW, если я удалю , все работает хорошо. Но мне нужно холст в моем приложении ... – user3131108

+0

Я попытался удалить холст в моем приложении, но я столкнулся с тем же исключением. Не всегда, но иногда.Итак, есть что-то принципиально неправильное, как я выделяю PointCollection или как я привязываю коллекцию к Polyline или есть что-то еще, если я удалю элемент из коллекции? Теперь я изменил код и не удалял элемент из коллекции, я скрываю Grid: такое же исключение, как и всегда. – user3131108

+0

Кажется, эта проблема. Я реализовал переопределение MeasureOverride. Но исключение бросает так или иначе. (http://phone.codeplex.com/workitem/10857) – user3131108

Смежные вопросы