如果“在附加到新的父Visual之前必须将指定的孩子与当前父Visual断开连接",如何调试视觉树?发生异常 [英] How to debug the visual tree if an "Must disconnect specified child from current parent Visual before attaching to new parent Visual" exception occurs

查看:70
本文介绍了如果“在附加到新的父Visual之前必须将指定的孩子与当前父Visual断开连接",如何调试视觉树?发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调试以下错误?

在附加到新的父Visual之前,必须断开指定的孩子与当前父Visual的连接.

Must disconnect specified child from current parent Visual before attaching to new parent Visual.

我确定我了解此 Exception 的含义,但是如果我错过了一些重要的内容,这就是我的意思:

I'm sure i understood the meaning of this Exception but in case I have missed something important here is what I think this means:

基于 FrameworkElement 的对象确实已经存在于可视树中的某个位置,我正尝试将其再次添加到树中的其他位置.

An object which based on FrameworkElement does already exist somewhere in the visual-tree and I am trying to add it again somewhere else in the tree.

要解决此问题,我有2个选择:

To work around this I have 2 options:

  1. 将其从视觉树中的当前位置删除,或
  2. 根据我的实现对其进行克隆.

到目前为止还不错,但是为什么此 Exception 不能告诉我我需要修改哪种类型的孩子?因为如果您尝试使用的对象包含多个子代,则必须在每个类中查找才能找到引发此 Exception 的对象.

So far so good but why does this Exception not tell me what type of child I need to modify? Because if the object you are trying to use contains multiple children you have to look in each class to may find the object which throws this Exception.

有找到对象的简便方法吗?我认为堆栈跟踪并没有真正的帮助.

Is there an easy way to find the object? I think the stack trace isn't really helpful.

这里是堆栈跟踪:

UnhandledException=System.ArgumentException: Must disconnect specified child from current parent Visual before attaching to new parent Visual.
   at System.Windows.Media.Visual.AddVisualChild(Visual child)
   at MS.Internal.Documents.FlowDocumentView.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.ScrollContentPresenter.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
   at System.Windows.Controls.ScrollViewer.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.StackPanel.StackArrangeHelper(IStackMeasure arrangeElement, IStackMeasureScrollData scrollData, Size arrangeSize)
   at System.Windows.Controls.StackPanel.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
   at System.Windows.Controls.ContentPresenter.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at MS.Internal.Helper.ArrangeElementWithSingleChild(UIElement element, Size arrangeSize)
   at System.Windows.Controls.ContentPresenter.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Border.ArrangeOverride(Size finalSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Control.ArrangeOverride(Size arrangeBounds)
   at System.Windows.Controls.DataGridCell.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.Controls.Grid.ArrangeOverride(Size arrangeSize)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.UIElement.UpdateLayout()
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
   at System.Windows.Window.SetRootVisual()
   at System.Windows.Window.SetRootVisualAndUpdateSTC()
   at System.Windows.Window.SetupInitialState(Double requestedTop, Double requestedLeft, Double requestedWidth, Double requestedHeight)
   at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
   at System.Windows.Window.CreateSourceWindowDuringShow()
   at System.Windows.Window.SafeCreateWindowDuringShow()
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at System.Windows.Window.Show()
   at System.Windows.Window.ShowDialog()
   at Speiseplandienst.ViewModels.BestellscheinUebersichtListVM.OnEdit() in C:\_\_\_\_\_\_\_\BestellscheinUebersichtListVM.cs:Line 30.
   at Framework.ListVM.Edit() in C:\_\_\_\_\_\_\Controls\ListVM.cs:Line 118.
   at Framework.ListVM.<get_EditCommand>b__8(Object param) in C:\_\_\_\_\_\_\Controls\ListVM.cs:Line 101.
   at Framework.RelayCommand.Execute(Object parameter) in C:\_\_\_\Framework\Tools\RelayCommand.cs:Line 132.
   at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at Speiseplandienst.MainRun.Main(String[] args) in C:\_\_\_\_\_\_\Main.cs:Line 18.

推荐答案

此错误可能有许多不同的原因.例如,如果您尝试多次将同一 Visual 对象添加到UI集合控件中,则会发生此错误.如果您尝试将选定的项(UI对象)从一个 ListBox 添加到另一个(而不仅仅是添加 data ),则会出现此错误.如果您尝试将 Image 对象设置为UI中已经存在的另一个 Image 对象,而不是设置 Image的 Source 属性替换为当前 Image 的图片,您会收到此错误.

This error can have many different causes. For example, if you try to add the same Visual object into a UI collection control more than once, this error will occur. If you try to add the selected items (UI objects) from one ListBox to another (rather than just adding the data), you will get this error. If you try to set an Image object to another Image that is already in the UI instead of setting the Source property of the Image to that of the current Image, you will get this error.

如果没有看到您的代码,我们将无法弄清为什么从堆栈跟踪中得到此错误...我想您是在 ShowDialog()时得到此错误的原因被称为,但是那里没有太多线索,除了问题是在该对话框或视图中可能是 .

Without seeing your code, it will be impossible for us to work out why you got this error... from your stack trace, I'm guessing that you get this error when ShowDialog() is called, but there's not much of a clue there except that the problem is probably in that dialog or view.

希望您现在对问题有所了解,您 可以自己解决问题.

Hopefully now that you understand the problem a little bit better, you may be able to fix it yourself.

这篇关于如果“在附加到新的父Visual之前必须将指定的孩子与当前父Visual断开连接",如何调试视觉树?发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆