We get this error and stack trace pretty often when clearing a large number of annotations from our CustomSourceCollectionBase. While we are using a custom collection, the call is made on a SourceCollectionBase function (Clear()). We’ve tried figuring out how to avoid this and why this happens but it appears to be something in the style of a BoxAnnotationForMvvm. Any help/guidance on this?
2024-11-06 07:46:42.545 -06:00 [Error] Exception: Cyclic reference found while evaluating the Style property on element 'SciChart.Charting.Visuals.Annotations.BoxAnnotationForMvvm'. in TimeLineViewModel
at System.Windows.FrameworkElement.UpdateStyleProperty()
at System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
at System.Windows.FrameworkElement.AddLogicalChild(Object child)
at System.Windows.Controls.UIElementCollection.AddInternal(UIElement element)
at SciChart.Core.Extensions.PanelExtensions.SafeAddChild(Panel panel, Object child, Int32 index)
at csb.rsp(IAnnotationCanvas hmb, Object hmc, Int32 hmd)
at SciChart.Charting.Visuals.Annotations.AnnotationBase.Update(ICoordinateCalculator`1 xCoordinateCalculator, ICoordinateCalculator`1 yCoordinateCalculator)
at SciChart.Charting.Visuals.Annotations.AnnotationBase.TryUpdate(ICoordinateCalculator`1 xCalc, ICoordinateCalculator`1 yCalc)
at SciChart.Charting.Visuals.Annotations.AnnotationBase.Refresh()
at SciChart.Charting.Visuals.Annotations.AnnotationBase.OnRenderablePropertyChanged(DependencyObject d, 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.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.StyleHelper.InvalidateContainerDependents(DependencyObject container, FrugalStructList`1& exclusionContainerDependents, FrugalStructList`1& oldContainerDependents, FrugalStructList`1& newContainerDependents)
at System.Windows.StyleHelper.DoStyleInvalidations(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle)
at System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
at System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, 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.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.FrameworkElement.UpdateStyleProperty()
at System.Windows.TreeWalkHelper.InvalidateOnTreeChange(FrameworkElement fe, FrameworkContentElement fce, DependencyObject parent, Boolean isAddOperation)
at System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
at System.Windows.FrameworkElement.RemoveLogicalChild(Object child)
at System.Windows.Controls.UIElementCollection.RemoveInternal(UIElement element)
at SciChart.Core.Extensions.PanelExtensions.SafeAddChild(Panel panel, Object child, Int32 index)
at csb.rsp(IAnnotationCanvas hmb, Object hmc, Int32 hmd)
at SciChart.Charting.Visuals.Annotations.AnnotationBase.Update(ICoordinateCalculator`1 xCoordinateCalculator, ICoordinateCalculator`1 yCoordinateCalculator)
at SciChart.Charting.Visuals.Annotations.AnnotationBase.TryUpdate(ICoordinateCalculator`1 xCalc, ICoordinateCalculator`1 yCalc)
at SciChart.Charting.Visuals.Annotations.AnnotationBase.Refresh()
at SciChart.Charting.Visuals.Annotations.AnnotationBase.OnRenderablePropertyChanged(DependencyObject d, 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.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
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 SciChart.Charting.Model.ChartSeries.SourceCollectionBase`2.ClearItems()
at Orchid.Common.UserControls.Common.CustomSourceCollectionBase`2.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args) in D:\source\Orchid\Orchid\Orchid.Common.UserControls\Common\CustomSourceCollectionBase.cs:line 72
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at DynamicData.Binding.ObservableCollectionExtended`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in /_/src/DynamicData/Binding/ObservableCollectionExtended.cs:line 158
at DynamicData.Binding.ObservableCollectionExtended`1.<SuspendNotifications>b__10_0() in /_/src/DynamicData/Binding/ObservableCollectionExtended.cs:line 143
at System.Reactive.Disposables.AnonymousDisposable.Dispose()
at DynamicData.Binding.ObservableCollectionAdaptor`1.Adapt(IChangeSet`1 changes) in /_/src/DynamicData/Binding/ObservableCollectionAdaptor.cs:line 67
at DynamicData.ObservableListEx.<>c__DisplayClass0_0`1.<Adapt>b__1(IChangeSet`1 changes) in /_/src/DynamicData/List/ObservableListEx.cs:line 53
at System.Reactive.Linq.ObservableImpl.Select`2.Selector._.OnNext(TSource value)
- Matthew Trahan asked 4 weeks ago
-
Hi Matthew, Thanks for your inquiry. I am going to discuss this with our team and will get back to you with an update. Kind regards, Lex, Scichart Technical Support Engineer
-
Thanks, Lex! You’re right about our custom collection setting the DataContext, and based on your answer I was able to figure out that I could set the Style to null and it looks like the exception is gone now.
- You must login to post comments
Hi Matthew,
We’ve discussed your inquiry.
Most probably this happens because the SourceCollection creates a UIElement Annotation and sets the DataContext.
Unfortunately, we cannot help much here because you use a custom SourceCollection.
However, the following Styles that are used as the default Style for BoxAnnotationForMVVM, can give you some hints on which property is causing the Cyclic reference exception:
<Style
x:Key="MvvmBoxAnnotationBaseStyle"
BasedOn="{StaticResource MvvmBaseAnnotationStyle}"
TargetType="a:BoxAnnotation">
<Setter Property="BorderBrush">
<Setter.Value>
<me:ThemeBinding DefaultPath="RubberBandStrokeBrush">
<me:ThemeBinding.BindingsCollection>
<me:BindingInfo Binding="{Binding BorderBrush}" />
</me:ThemeBinding.BindingsCollection>
</me:ThemeBinding>
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<me:ThemeBinding DefaultPath="RubberBandFillBrush">
<me:ThemeBinding.BindingsCollection>
<me:BindingInfo Binding="{Binding Background}" />
</me:ThemeBinding.BindingsCollection>
</me:ThemeBinding>
</Setter.Value>
</Setter>
<Setter Property="BorderThickness" Value="{Binding BorderThickness, Mode=TwoWay}" />
<Setter Property="Margin" Value="{Binding Margin, Mode=TwoWay}" />
<Setter Property="Template" Value="{StaticResource BoxAnnotationTemplate}" />
<Setter Property="CornerRadius" Value="{Binding CornerRadius, Mode=TwoWay}" />
And one more:
<Style x:Key="MvvmBaseAnnotationStyle" TargetType="a:AnnotationBase">
<Style.Setters>
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Foreground">
<Setter.Value>
<me:ThemeBinding DefaultPath="TickTextBrush">
<me:ThemeBinding.BindingsCollection>
<me:BindingInfo Binding="{Binding Path=Foreground}" />
</me:ThemeBinding.BindingsCollection>
</me:ThemeBinding>
</Setter.Value>
</Setter>
<Setter Property="FontSize" Value="12" />
<Setter Property="XAxisId" Value="{Binding XAxisId, Mode=TwoWay}" />
<Setter Property="YAxisId" Value="{Binding YAxisId, Mode=TwoWay}" />
<Setter Property="X1" Value="{Binding X1, Mode=TwoWay}" />
<Setter Property="X2" Value="{Binding X2, Mode=TwoWay}" />
<Setter Property="Y1" Value="{Binding Y1, Mode=TwoWay}" />
<Setter Property="Y2" Value="{Binding Y2, Mode=TwoWay}" />
<Setter Property="AnnotationCanvas" Value="{Binding AnnotationCanvas, Mode=TwoWay}" />
<Setter Property="CoordinateMode" Value="{Binding CoordinateMode, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="IsHidden" Value="{Binding IsHidden, Mode=TwoWay}" />
<Setter Property="DragDirections" Value="{Binding DragDirections, Mode=TwoWay}" />
<Setter Property="ResizeDirections" Value="{Binding ResizeDirections, Mode=TwoWay}" />
<Setter Property="CanEditText" Value="{Binding CanEditText, Mode=TwoWay}" />
<Setter Property="IsEditable" Value="{Binding IsEditable, Mode=TwoWay}" />
<Setter Property="ToolTipService.ToolTip" Value="{Binding Tooltip, Mode=TwoWay}" />
<Setter Property="chartSeries:AnnotationsSourceCollection.StyleKey"
Value="{Binding StyleKey, Mode=TwoWay}" />
<Setter Property="DragEndedCommand" Value="{Binding DragEndedCommand}" />
<Setter Property="DragDeltaCommand" Value="{Binding DragDeltaCommand}" />
<Setter Property="DragStartedCommand" Value="{Binding DragStartedCommand}" />
<Setter Property="UnselectedCommand" Value="{Binding UnselectedCommand}" />
<Setter Property="SelectedCommand" Value="{Binding SelectedCommand}" />
<Setter Property="IsHiddenChangedCommand" Value="{Binding IsHiddenChangedCommand}" />
</Style.Setters>
Kind regards,
Lex,
SciChart Technical Support Engineer
- Lex answered 3 weeks ago
- You must login to post comments
Please login first to submit.