Home Dashboard Directory Help
Search

Specified element is already the logical child of another element. Disconnect it first. by Đonny


Status: 

Active


15
0
Sign in
to vote
Type: Bug
ID: 496959
Opened: 10/9/2009 12:16:55 PM
Access Restriction: Public
1
Workaround(s)
view
10
User(s) can reproduce this bug

Description

When WPF ComboBox item has complex tooltip InvalidOperationException "Specified element is already the logical child of another element. Disconnect it first." is thrown when item is hovered, selected; combobox is closed and reopened and item is hovered again.

This issue was reported by several users at http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/07d2a0bb-af63-44d0-be05-cd31aefa8110?prof=required.
Details
Sign in to post a comment.
Posted by Mayank Gaur on 1/27/2014 at 4:26 AM
Any updates on this? This is affecting our users leading to random crashes. The workaround mentioned is impractical for a large scale enterprise application. Eagerly waiting to hear back.
Posted by MickleKulls on 9/12/2011 at 11:37 PM
For Varsha Mahadevan,

This issue has not been fixed in dot net 4.0, I have reproduced it using the latest and greatest of everything as of 13-Sep-2011.

The suggested workaround does work but this has the side effect of making the tooltips not update if the value is bound. For example, I have a staff member named Bob, I have a tooltip that shows his name, someone changes his name to Robert and the tooltip still says Bob. This can be fixed with a PropertyChanged event but this is a pain. The reason it is a pain is because I define a property, eg StaffToolTip, that returns the tooltip for a staff. The property is based off many other properties like firstname, familyname etc. So in every one of those props I have to raise an event for tooltip changed.
Posted by small_mountain_0705 on 2/22/2011 at 12:05 PM
The workaround of allocating your own ToolTip rather than just setting a TextBlock or whatever as the tool tip does seem to work.

Eric
Posted by small_mountain_0705 on 2/22/2011 at 11:44 AM
My app is built and run with production .NET 4, and this bug, at least with menu tooltips, is still highly reproducible.

Eric
Posted by Kasimier Buchcik on 10/10/2010 at 6:51 AM
I'm encountering the same issue with nested UserControls in the designer of VS 2010. If MS would care to explain the reasons why this exception occurs, then we might find some workarounds. A year of silence does not help.
Posted by MikeT1201 on 8/12/2010 at 1:15 PM
Unfortunately, I have encountered this exact bug but in a different place. Menu tooltips are doing this as well. I have a listbox with a simple TextBlock tooltip on each row. when right-clicking on different rows of the listbox, and moving the mouse slightly after I let go of the right mouse button, I receive an exception: "Specified element is already the logical child of another element. Disconnect it first."

The workaround published in this article seems to make the issue go away
Posted by Đonny on 12/10/2009 at 2:27 PM
I have just experienced the error on .NET 3.5 SP1 x64 as well :-(
It's not as easy to reproduce as on x86 3.5 SP1. Hover, select, hover, select another, hove, ... several times - it'll crash.
Then I tried to reproduce it in under 4.0 Beta 2 x64, successfully :-(.

Call stack:
at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
at System.Windows.FrameworkElement.AddLogicalChild(Object child)
at 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.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
at System.Windows.Controls.PopupControlService.RaiseToolTipOpeningEvent()
at System.Windows.Threading.DispatcherTimer.FireTick(Object unused)
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.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(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.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(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.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.ShowDialog()
at Caps.Console.winMain.cmdNew_Executed(Object sender, ExecutedRoutedEventArgs e) in D:\Users\Honza\Documents\Programy\Caps\CapsConsole\winMain.xaml.vb:line 102
at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
at System.Windows.Input.CommandManager.ExecuteCommandBinding(Object sender, ExecutedRoutedEventArgs e, CommandBinding commandBinding)
at System.Windows.Input.CommandManager.FindCommandBinding(CommandBindingCollection commandBindings, Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
at System.Windows.Input.CommandManager.FindCommandBinding(Object sender, RoutedEventArgs e, ICommand command, Boolean execute)
at System.Windows.Input.CommandManager.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.RoutedCommand.ExecuteImpl(Object parameter, IInputElement target, Boolean userInitiated)
at System.Windows.Input.CommandManager.TranslateInput(IInputElement targetElement, InputEventArgs inputEventArgs)
at System.Windows.UIElement.OnKeyDownThunk(Object sender, KeyEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, 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.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
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.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.TranslateAndDispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at Caps.Console.Application.Main() in D:\Users\Honza\Documents\Programy\Caps\CapsConsole\obj\Debug\Application.g.vb:line 82
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Posted by Đonny on 11/27/2009 at 9:48 AM
I've discovered that this problem is x86-specific. My application is set to build as AnyCPU, so after I bought a new laptop with x64 Windows 7, it worked there, but when I've created a new WPF application in VS2010 just to test the issue it reappeared because default platform in VS 2010 Beta 2 is x86 (surprise, surprise).
Buggy configuration: VS 2010 Beta 2, Windows 7 Ultimate CZ x64, Build: Debug|x86, Target framework: 3.5
Working configuration: VS 2010 Beta 2, Windows 7 Ultimate CZ x64, Build: Debug|AnyCPU, Target framework: 3.5
Posted by Đonny on 11/18/2009 at 1:43 PM
Hi,
I'm unhappy to inform you that I'm experiencing the same problem with Visual Studio 2010 Beta 2 on Windows 7 x64.
Download attached project, run it, open combo box, hover over combobox item so tooltip is shown, select the item, open combobox again, hover over currently selected item again so tooltip is shown:
Specified element is already the logical child of another element. Disconnect it first.
Posted by Varsha Mahadevan - MSFT on 10/14/2009 at 3:56 PM
Hi,

I am happy to inform you that this issue has been fixed in the upcoming .Net 4.0 release.

Thanks
Varsha
Posted by Microsoft on 10/13/2009 at 2:42 AM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Varsha Mahadevan - MSFT on 10/14/2009 at 3:57 PM
You could wrap your ToolTip Rectangle in an explicit ToolTip object. This should fix the issue.

To workaround this issue, you could wrap the Rectangle in a ToolTip instance of your own.



<Grid.ToolTip>

<ToolTip>
<Rectangle Grid.Column="0" Width="100" Height="100" Stroke="Black" StrokeThickness="1" Fill="{Binding Value}"/>

</ToolTip>
</Grid.ToolTip>