Hi,
We inherited from VerticalSliceModifier and then add a VerticalLineAnnotation, but the ExportToFile failed.What is the reason for this, and how can one correctly inherit from VerticalSliceModifier? The code below can simply reproduce this error. My debugging results show that OnAnnotationCollectionChanged is executed when generating the image, and there are 2 Annotations in the sender.
public class TestModfiy: VerticalSliceModifier
{
public override void OnAttached()
{
base.OnAttached();
}
protected override void OnAnnotationCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
base.OnAnnotationCollectionChanged(sender, args);
}
public override void OnDetached()
{
base.OnDetached();
}
}
The Exception:
ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
参数名: index
Stack Trace:
在 System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
在 System.Collections.Generic.List1.get_Item(Int32 index)1 ard)
在 SciChart.Charting.Visuals.SciChartSurface.CreateCloneOfSurfaceInMemory(Size newSize)
在 SciChart.Charting.Visuals.SciChartSurfaceBase.mro(ExportType arb, Boolean arc, Nullable
在 SciChart.Charting.Visuals.SciChartSurfaceBase.ExportToFileInternal(String fileName, ExportType exportType, Boolean useXamlRenderSurface, Nullable1 size)1 size)
在 SciChart.Charting.Visuals.SciChartSurfaceBase.ExportToFile(String fileName, ExportType exportType, Boolean useXamlRenderSurface)
在 SciChart.Examples.ExternalDependencies.Controls.Toolbar2D.CustomModifiers.CustomExportModifier.Export(String filter, Boolean useXaml, Nullable
在 SciChart.Examples.ExternalDependencies.Controls.Toolbar2D.CustomModifiers.CustomExportModifier.<.ctor>b__16_2()
在 MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
在 System.Windows.Controls.Primitives.ButtonBase.OnClick()
在 System.Windows.Controls.Button.OnClick()
在 System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
在 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
在 System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
在 System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
在 System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
在 System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
在 System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
在 System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
在 System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
在 System.Windows.Input.InputManager.ProcessStagingArea()
在 System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
在 System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
在 System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
在 System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
- wei zhao asked 1 month ago
- last edited 1 month ago
- You must login to post comments
Hi Wei Zhao,
Thank you for contacting us.
If you have any customizations for your chart control, we recommend overriding the CreateCloneOfSurfaceInMemory() method and adding these customizations there.
This allows to properly modify the cloned chart before export.
Please see the “Overriding CreateCloneOfSurfaceInMemory” section of the following documentation article:
SciChart WPF Documentation – Export Troubleshooting _ WPF Chart Documentation
You can also find this approach described in the “Advanced Export with Chart Customization” section of the following article:
SciChart WPF Documentation – Screenshots, Printing and Export _ WPF Chart Documentation
If you already do this in your application, we would appreciate if you could share a small example project showing your approach for investigation on our side.
You can also modify one of our examples from the WPF Examples suite for your convenience:
https://www.scichart.com/examples/wpf-chart/
Kind regards,
Lex S., MSEE
SciChart Technical Support Engineer
- Lex answered 1 month ago
- You must login to post comments
Hi Lex,
Thank you for your guidance.
Solution
I’ve resolved the issue by adding a custom Tag marker to the VerticalLineAnnotation instances created in my derived
class. In the OnAttached override, I now check if such a marked annotation already exists – if it does,
I skip calling base.OnAttached() to prevent the base class from creating duplicate annotations during the
cloning process.
Here’s the key part of my solution:
public override void OnAttached()
{
// Check if annotations with our custom tag already exist (clone scenario)
if (VerticalLines.Any(x => x.Tag?.ToString() == "myVerticalSliceModifierCreated"))
{
// Skip base.OnAttached() to avoid duplicate annotation creation
ReceiveHandledEvents = true;
SeriesData.PropertyChanged += SeriesData_PropertyChanged;
sliceAnnotationStyle = (ParentSurface as FrameworkElement)?.TryFindResource(SliceAnnotationStyleKey) as Style;
return;
}
base.OnAttached();
// ... rest of initialization
}
This approach prevents the ArgumentOutOfRangeException during export.
Additional Questions
- We bind some external data (Deltas) that is displayed outside the chart area but positioned relative to it. If we want to include this external data in the exported image, does SciChart provide any built-in support for this, or would we need to implement our own custom export logic?
- How does
VerticalSliceModifierhandle serialization internally? Understanding this would help ensure our derived class works correctly in all scenarios.
Kind regards,
Wei Zhao
- wei zhao answered 1 month ago
- last edited 1 month ago
Hi Wei Zhao, Thank you for your update. I’m glad you found a solution! I’m going to forward your additional questions to our team for further discussion. We’ll get back to you as soon as we have an update. Kind regards, Lex
- You must login to post comments
Please login first to submit.

