WPF崩溃不在我们的代码中



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

以下是调用堆栈。。。

2014年6月26日下午3:29:05:[FATAL]System.InvalidOperationException:指定的元素已经是另一个元素的逻辑子元素。先断开连接。位于System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)位于System.Windows.FrameworkElement.AddLogicalChild(对象子级)位于System.Windows.Controls.ContentControl.OnContentChanged(对象oldContent,对象newContent)位于System.Windows.Controls.TabItem.OnContentChanged(对象oldContent,对象newContent)位于System.Windows.Controls.ContentControl.OnContentChanged(DependencyObject d,DependencyProperty ChangedEventArgs e)位于System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)位于System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)位于System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs参数)在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex EntryIndex、DependencyProperty dp、PropertyMetadata元数据、EffectiveValueEntry oldEntry、EffectiveValue Entry和newEntry、布尔强制DeferredReference、布尔强制CurrentValue、OperationType OperationType)位于System.Windows.StyleHelper.ApplyStyleOrTemplateValue(FrameworkObject fo,DependencyProperty dp)位于System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject容器,FrugalStructList1& exclusionContainerDependents, FrugalStructList1&oldContainerDependences,Frugal StructList`1&newContainerDependencies)位于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,DependencyProperty ChangedEventArgs e)位于System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)位于System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)位于System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs参数)在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex EntryIndex、DependencyProperty dp、PropertyMetadata元数据、EffectiveValueEntry oldEntry、EffectiveValue Entry和newEntry、布尔强制DeferredReference、布尔强制CurrentValue、OperationType OperationType)位于System.Windows.DependencyObject.SetValueCommon(DependencyProperty-dp,Object值,PropertyMetadata元数据,布尔强制DeferredReference,布尔强制CurrentValue,OperationType OperationType,布尔isInternal)位于System.Windows.Controls.ItemsControl.ApplyItemContainerStyle(DependencyObject容器,Object项)位于System.Windows.Controls.ItemsControl.MS.Internal.Control.IGeneratorHost.PrepareItemContainer(DependencyObject容器,Object项)位于System.Windows.Controls.ItemContainerGenerator.System.Window.Controls.Primities.IItemContainerGenerator.PrepareItemContainer(DependencyObject容器)位于System.Windows.Controls.Panel.GenerateChildren()位于System.Windows.Controls.Panel.OnItemsChangedInternal(对象发送器,ItemsChangedEventArgs参数)位于System.Windows.Controls.Panel.OnItemsChanged(对象发送器,ItemsChangedEventArgs参数)位于System.Windows.Controls.ItemContainerGenerator.OnRefresh()位于System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(对象发送器,NotifyCollectionChangedEventArgs参数)位于System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(类型managerType,Object sender,EventArgs e)位于System.Windows.WeakEventManager.EDeliverEventToList(对象发送方、EventArgs参数、ListerList列表)位于System.Windows.WeakEventManager.EDeliverEvent(对象发送方,EventArgs参数)位于System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(对象发送方,NotifyCollectionChangedPEventArgs参数)位于System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(对象发送方,NotifyCollectionChangedEventArgs e)位于System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)位于System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView视图)位于System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable值)位于System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d,DependencyProperty ChangedEventArgs e)位于System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)位于System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)位于System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs参数)在System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex EntryIndex、DependencyProperty dp、PropertyMetadata元数据、EffectiveValueEntry oldEntry、EffectiveValue Entry和newEntry、布尔强制DeferredReference、布尔强制CurrentValue、OperationType OperationType)位于System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)位于System.Windows.Data.BindingExpressionBase.Invalidate(布尔值isASubPropertyChange)位于System.Windows.Data.BindingExpression.TransferValue(对象newValue,布尔值isASubPropertyChange)位于System.Windows.Data.BindingExpression.Activate(对象项)位于System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt尝试)位于System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(布尔lastChance)位于MS.Internal.Data.DataBindEngine.Task.Run(布尔lastChance)位于MS.Internal.Data.DataBindEngine.Run(对象参数)位于MS.Internal.DataBindEngine.OnLayoutUpdated(对象发送器,EventArgs e)位于System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()位于System.Windows.ContextLayoutManager.UpdateLayout()位于System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)位于System.Windows.Media.MediaContext.IInvokeOnRenderCallback.DoWork[()位于System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()位于System.Windows.MediaContext.RenderMessageHandlerCore(对象大小为CompositionTarget)位于System.Windows.MediaContext.RenderMessage处理程序(对象大小为CompositionTarget)位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调、对象参数、Int32 numArgs)位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源、委托方法、对象参数、Int32 numArgs、委托catchHandler)

您之所以出现此错误,是因为您试图将控件(Visual)设置为另一个Visual的子控件,而没有首先将其从可视化树中删除。Visual永远不可能在两个位置的可视化树中。

困难的部分将是追踪Visual被插入树中两次的内容。你将很难在调试器中捕捉到它(认为这几乎是不可能的),所以你必须尝试一些更具创造性的调试方法。如果你能始终如一地重现这个问题,也许可以试着一次剥离一个Visual,看看是哪个Visual导致了这个问题。如果您有一些自定义控件正在使用一些较低级别的可视化树功能,那么这些控件将是非常可疑的。先看一看。

相关内容

最新更新