The item is already a descendant of another item.

I get the following error in a Silverlight application. But I can’t understand what the problem is. If I debug it, then it does not break into anything in the code, it just fails in this callstack structure with only the frame code. Is there a way to get more information about which part of the Silverlight application is the problem in this case.

Message: Sys.InvalidOperationException: ManagedRuntimeError error # 4004 in control 'Xaml1': System.InvalidOperationException: Element is already the child of another element.
at MS.Internal.XcpImports.CheckHResult (UInt32 hr)
at MS.Internal.XcpImports.Collection_AddValue [T] (PresentationFrameworkCollection`1 collection, CValue value)
at MS.Internal.XcpImports.Collection_AddDependencyObject [T] (PresentationFrameworkCollection`1 collection, DependencyObject value)
at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject (DependencyObject value)
at System.Windows.Controls.UIElementCollection.AddInternal (UIElement value)
at System.Windows.PresentationFrameworkCollection`1.Add (T value)
at System.Windows.Controls.AutoCompleteBox.OnApplyTemplate ()
at System.Windows.FrameworkElement.OnApplyTemplate (IntPtr nativeTarget)

XAML for AutoCompeletBox, which is in context:

<tk:AutoCompleteBox 
    x:Name="acName" 
    Grid.Row="0" 
    Grid.Column="1" 
    LostFocus="acName_LostFocus"
    Height="20"
    Width="80" 
    HorizontalAlignment="Left"/>
+3
source share
4 answers

, .

XAML, , .

0

, - , ( "", , ..).

In cases where a particular control does not work, there is not enough information to digest.

0
source

Simple and stupid solution:

public class AutoCompleteTextBox : AutoCompleteBox
    {
        public override void OnApplyTemplate()
        {
            try
            {
                base.OnApplyTemplate();
            }
            catch { }
        }
    }
-4
source

Source: https://habr.com/ru/post/1739177/


All Articles