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:51Type : System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Message : Specified element is already the logical child of another element. Disconnect it first.Source : PresentationFrameworkHelp link : Data : System.Collections.ListDictionaryInternalTargetSite : Void ChangeLogicalParent(System.Windows.DependencyObject)HResult : -2146233079Stack 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?
In addition to that, the sample provided here does not work at all with Infragistics v.19.1.
The Invalid operation exception is thrown right away.
Hello Andrew,
is there any progress on that matter ? 3 years later I am also facing the same issue.
Best regards
Thanks Andrew, it's good to know it's not just me...
In this case, since the chart series are statically defined, I'll probably just do as you suggest and create my own legend.
Thanks again.
Hello gregorach,
I have been investigating into this behavior that you are referring to, and I am able to reproduce this behavior with the XamDataChart and a Legend inside of a tab control. This is unexpected behavior, and as such, I have asked our engineering staff to examine it further. To ensure it receives attention, I have logged this in our internal tracking systems with a development ID of 245889.
I have also created you a private support case so you can track this issue. It has an ID of CAS-188721-C0X2H9 and you can access it at https://es.infragistics.com/my-account/support-activity.
Regarding a workaround for this issue, it appears that the issue is mainly occurring in the Legend's constructor, as this is the last call to Infragistics code prior to the exception being thrown. I am rather unsure at the moment as to why the Legend is only throwing this exception on the second time opening the tab, though. It seems something is not letting go of the ContentControl legend items correctly. Perhaps removing the Legend from the tab when you exit the tab and then re-applying it would work in this case, although there is a chance the exception would still happen there. If you really wish to have a wrapping legend in this case, I would actually probably recommend simply using a WrapPanel, and for each Series element in your XamDataChart, add an item to it. This would allow you to essentially create your own Legend, and avoid this issue.
I will be updating the private support case with further information on development issue 245889 shortly. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer