WPF崩溃不在我们的代码中

时间:2014-06-26 21:47:21

标签: wpf crash

有没有人知道如何在WPF中解决崩溃,其中调用堆栈完全在Windows代码中。

以下是调用堆栈......

  

2014/6/26 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)       在System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)       在System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)       在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)       在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata metadata,EffectiveValueEntry oldEntry,EffectiveValueEntry& newEntry,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType)       在System.Windows.StyleHelper.ApplyStyleOrTemplateValue(FrameworkObject fo,DependencyProperty dp)       在System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject容器,FrugalStructList 1& exclusionContainerDependents, FrugalStructList 1& oldContainerDependents,FrugalStructList`1& newContainerDependents)       在System.Windows.StyleHelper.DoStyleInvalidations(FrameworkElement fe,FrameworkContentElement fce,Style oldStyle,Style newStyle)       在System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe,FrameworkContentElement fce,Style oldStyle,Style newStyle,Style& styleCache)       在System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)       在System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)       在System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)       在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)       在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata metadata,EffectiveValueEntry oldEntry,EffectiveValueEntry& newEntry,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType)       在System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp,Object value,PropertyMetadata metadata,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType,Boolean isInternal)       在System.Windows.Controls.ItemsControl.ApplyItemContainerStyle(DependencyObject容器,对象项)       在System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject容器,对象项)       在System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject容器)       在System.Windows.Controls.Panel.GenerateChildren()       在System.Windows.Controls.Panel.OnItemsChangedInternal(Object sender,ItemsChangedEventArgs args)       在System.Windows.Controls.Panel.OnItemsChanged(Object sender,ItemsChangedEventArgs args)       在System.Windows.Controls.ItemContainerGenerator.OnRefresh()       在System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender,NotifyCollectionChangedEventArgs args)       在System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(类型managerType,Object sender,EventArgs e)       在System.Windows.WeakEventManager.DeliverEventToList(Object sender,EventArgs args,ListenerList list)       在System.Windows.WeakEventManager.DeliverEvent(Object sender,EventArgs args)       在System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender,NotifyCollectionChangedEventArgs args)       在System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender,NotifyCollectionChangedEventArgs e)       在System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)       在System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView视图)       在System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable value)       在System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)       在System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)       在System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)       在System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)       在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex,DependencyProperty dp,PropertyMetadata metadata,EffectiveValueEntry oldEntry,EffectiveValueEntry& newEntry,Boolean coerceWithDeferredReference,Boolean coerceWithCurrentValue,OperationType operationType)       在System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)       在System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)       在System.Windows.Data.BindingExpression.TransferValue(Object newValue,Boolean isASubPropertyChange)       在System.Windows.Data.BindingExpression.Activate(对象项)       在System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt尝试)       在System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)       在MS.Internal.Data.DataBindEngine.Task.Run(布尔值lastChance)       在MS.Internal.Data.DataBindEngine.Run(Object arg)       在MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender,EventArgs e)       在System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()       在System.Windows.ContextLayoutManager.UpdateLayout()       在System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)       在System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()       在System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()       在System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)       在System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)       在System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调,对象args,Int32 numArgs)       在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate方法,Object args,Int32 numArgs,Delegate catchHandler)

1 个答案:

答案 0 :(得分:1)

您收到此错误的原因是您尝试将控件(Visual)设置为另一个Visual的子项而不先将其从可视树中删除。 Visual在两个地方永远不会出现在可视树中。

困难的部分是追踪Visual两次插入树中的内容。你将很难在调试器中捕获它(想想几乎不可能),所以你必须尝试一些更有创意的调试方法。如果您可以一致地重现问题,可以尝试一次一个地删除Visual,并查看哪个Visual导致问题。如果您有一些自定义控件正在使用某些较低级别的可视化树功能,那么这些将非常可疑。先看看它们。