Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
478
Chart legend WrapPanel template
posted

Hi.

I've followed the steps outlined here to change my Chart Legend to use a WrapPanel for its content presenter, which all works just fine... However, my chart is on a tab in a tab control, and if I select a different tab and then go back to the tab with the chart, it blows up with a fantastic pile of exceptions, of which the first is:

An exception of type 'System.InvalidOperationException' occurred and was caught.
--------------------------------------------------------------------------------
11/13/2017 14:40:51
Type : System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Specified element is already the logical child of another element. Disconnect it first.
Source : PresentationFramework
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ChangeLogicalParent(System.Windows.DependencyObject)
HResult : -2146233079
Stack Trace :    at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
   at System.Windows.FrameworkElement.AddLogicalChild(Object child)
   at System.Windows.Controls.UIElementCollection.InsertInternal(Int32 index, UIElement element)
   at Infragistics.Controls.Charts.Legend.<.ctor>b__6_0(Object o, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at Infragistics.Controls.Charts.Legend.AddChildInOrder(UIElement legendItem, ILegendSeries series)
   at Infragistics.Controls.Charts.Series.AssertLegendItems(LegendBase oldLegend, LegendBase newLegend)
   at Infragistics.Controls.Charts.Series.OnSeriesAttached()
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Is there a better way to change the chart legend template, or a way to prevent this exception from occurring when the tab containing the chart and legend is re-displayed?