Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

The element is already the child of another element in TabControl

$
0
0

I am working on Silverlight and in a very strange problem where it do not give any exception and do not break on running at breakpoints. So i kept a break point in app.xaml.cs at

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
 //something here
}

On debugging it break and i found that in "e" i have following unhandled exception:

{System.InvalidOperationException: The element is already the child of another element. 
    to MS.Internal.XcpImports.CheckHResult (UInt32 hr) 
    to MS.Internal.XcpImports.SetValue (IManagedPeerBase obj, DependencyProperty property, DependencyObject doh) 
    to MS.Internal.XcpImports.SetValue (IManagedPeerBase doh, DependencyProperty property, Object obj) 
    to System.Windows.DependencyObject.SetObjectValueToCore (DependencyProperty dp, Object value) 
    to System.Windows.DependencyObject.SetEffectiveValue (DependencyProperty property, EffectiveValueEntry & newEntry, Object newValue) 
    to System.Windows.DependencyObject.UpdateEffectiveValue (DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry & newEntry, ValueOperation operation) 
    to System.Windows.DependencyObject.RefreshExpression (DependencyProperty dp) 
    System.Windows.Data.BindingExpression.SendDataToTarget to () 
    System.Windows.Data.BindingExpression.SourceAcquired to () 
    to System.Windows.Data.Binding.EnsureBreakPoint (BindingDebugState debugState, Action callback, Boolean canDelay) 
    to System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, e DataContextChangedEventArgs) 
    to System.Windows.Data.BindingExpression.DataContextChanged (Object sender, e DataContextChangedEventArgs) 
    to System.Windows.FrameworkElement.OnDataContextChanged (DataContextChangedEventArgs e) 
    to System.Windows.FrameworkElement.OnTreeParentUpdated (DependencyObject newParent, Boolean bIsNewParentAlive) 
    to System.Windows.DependencyObject.UpdateTreeParent (IManagedPeer oldParent, IManagedPeer newParent, bIsNewParentAlive Boolean, Boolean keepReferenceToParent) 
    to MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate (oldParentElement IntPtr, IntPtr parentElement, IntPtr childElement, bIsParentAlive Byte, Byte bKeepReferenceToParent, Boolean canCreateParent)}


Now when it happens :

I have TabControl which has 3 Tab Items. One Tabitem show xml code, second show c# code andthe third (the Nasty one) shows UI elements created dynamically using c#.

Now the above TabControl (which already contains 3 TabItems) is stored as Content of another TabItem(result here in my code below) like this which is kind of parent of all:

(so you can see that first is "Result" then it contains "TabControl" and then it contains "3 TabItems") And thisresult is stored inObservableCollection<TabItem> result = new ObservableCollection<TabItem>();I mean it will have two tabitem like result. And each of my "result" in this collection is responsible for rendering informations of different object in the given three tab items(xml, code and UI elemnts rendering in Tabitem correspoding to selected result(tabitem) in this ObservableCollection list).

When problem occurs ? :

The problem occurs only when i switch from one result TabItem to another and then come back to the same "TabItem" (which is responsible for UI element rendering,Please note that it happens for this TabItem Only, Not other two) (Only for the third TabItem ofResult which i called "nasty" one, Which is supposed to be rendered UI Elements created dynamically).it crashes my project and gives that Unhandled exception

Could some one please let me know the cause of this problem with solution ? Thanks a lot.


EDIT : (please see in explain to avoid confusion)

Suppose i have two "Result" tabitems in my observable collection of TabItem and each "Result" represent different object and renders different UI element on clicking 3rd TabItem of the TabControl of each Result(TabItem). At start when i click the 3rd TabItem (nasty one, which Ui elemnts) of first "Result"it works fine now again i click on 3rd tab item of of second "Result" it still works fine and render UI elemnt replacing the first one.and now when second time when i click back to the 3rd TabItem of First "Result" then it carshes (I mean first i Clicked 3 rd tabitem of first Result then i clicked to 3rd TabItem of second Result, Until it worked fine and render two different UI elemnts on different click at same place but nowx when i go back to 3rd tabtem of first Result , It crashes the application with that exception) "I mean First->Second->First (crash)) ?"

Note: Please nOtethat i have done the binding of these three TabItems in c# dynamically.




Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>