WPF崩溃不在我们的代码中

有谁知道如何解决WPF中的调用堆栈完全在Windows代码中的崩溃。

以下是调用堆栈...

6/26/2014 3:29:05 PM:[致命] System.InvalidOperationException:指定的元素已经是另一个元素的逻辑子元素。 先断开它。 System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)在System.Windows.FrameworkElement.AddLogicalChild(Object child)System.Windows.Controls.ContentControl.OnContentChanged(Object oldContent,Object newContent)System.Windows.Controls.TabItem。 OnContentChanged(Object oldContent,Object newContent)System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)at System.Windows.DependencyObject.UpdateEffectiveValue上的System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationT 在System.Windows.StyleHelper的System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject容器,FrugalStructList 1& exclusionContainerDependents, FrugalStructList 1&oldContainerDependents,FrugalStructList`1&newContainerDependents)上的System.Windows.StyleHelper.ApplyStyleOrTemplateValue(FrameworkObject fo,DependencyProperty dp) System.Windows.FrameworkElement.OnStyleChanged处的System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe,FrameworkContentElement fce,Style oldStyle,Style newStyle,Style&styleCache)的DoStyleInvalidations(FrameworkElement fe,FrameworkContentElement fce,Style oldStyle,Style newStyle)(DependencyObject d, DependencyPropertyChangedEventArgs e)在System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)在System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEven System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyObject.setValueCommon(System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata metadata,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType) ,PropertyMetadata元数据,布尔coerceWithDeferredReference,布尔coerceWithCurrentValue,OperationType操作类型,布尔isInternal)在System.Windows.Controls.ItemsControl.ApplyItemContainerStyle(DependencyObject容器,对象项目)在System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost。在System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject容器)上System.Windows.Controls.Panel.GenerateChildren()在System.Windo上PrepareItemContainer(DependencyObject容器,对象项) 在System.Windows.Controls的System.Windows.Controls.ItemContainerGenerator.OnRefresh()处的System.Windows.Controls.Panel.OnItemsChanged(Object sender,ItemsChangedEventArgs args)处的ws.Controls.Panel.OnItemsChangedInternal(Object sender,ItemsChangedEventArgs args)。 ItemContainerGenerator.OnCollectionChanged(Object sender,NotifyCollectionChangedEventArgs args)在System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType,Object sender,EventArgs e)at System.Windows.WeakEventManager.DeliverEventToList(Object sender,EventArgs args ,System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender,NotifyCollectionChangedEventArgs args)在System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(对象发件人,System.Windows.WeakEventManager.DeliverEvent(对象发件人,EventArgs参数),ListenerList列表) NotifyCollectionChangedEventArgs e)在System.Windows.Data.CollectionView.OnCol System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView视图)在System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable值)在System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)lectionChanged(NotifyCollectionChangedEventArgs args)在System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)上System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)上System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs参数)在System.Windows.DependencyObject.UpdateEffectiveValue(entryIndex entryIndex,DP的DependencyProperty ,PropertyMetadata元数据,EffectiveValueEntry oldEntry,EffectiveValueEntry&newEntry,布尔coerceWithDeferredReference,布尔coerceWithCurrentValue,OperationType操作类型)在System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)在System.Windows.Data.Bin 在System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt)上System.Windows.Data.BindingExpression.Activate(Object item)处System.Windows.Data.BindingExpression.TransferValue(Object newValue,Boolean isASubPropertyChange)上的dingExpressionBase.Invalidate(Boolean isASProPropertyChange)尝试)在MS.Internal.Data.DataBindEngine.Task.Run(布尔lastChance)在MS.Internal.Data.DataBindEngine.Run在System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(布尔lastChance) (Object arg)at System.Windows.ContextLayoutManager.UpdateLayout()at System.Windows.ContextLayoutManager.UpdateLayoutCallback()方法System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()上的MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender,EventArgs e)对象arg)在System.Windows.Media.Media.Media.MediaContext.InvokeOnRenderCallback.DoWork()在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()在System.Windows.Media.MediaContext.RenderMessageHandlerCor 在System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,Int32 numArgs)在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen((对象resizedCompositionTarget)对象源,委托方法,对象参数,Int32 numArgs,委托catchHandler)


你得到这个错误是因为你试图将控件(Visual)设置为另一个Visual的子项,而没有先从可视树中删除它。 视觉不能在两个地方的视觉树中。

困难的部分是要追踪Visual插入到树中两次。 你将很难在调试器中捕获它(想想几乎是不可能的),所以你必须尝试一些更有创意的调试方法。 如果您可以持续重现此问题,则可以尝试一次性删除一个Visual,然后查看哪个Visual以这种方式导致问题。 如果您有一些自定义控件正在使用一些较低级别的可视化树功能,这些将会非常令人怀疑。 先看看他们。

链接地址: http://www.djcxy.com/p/30525.html

上一篇: WPF Crash not in our code

下一篇: Random InvalidOperationException on application startup