0

I want to add an parameter to AnnotationCollection class. Because it is sealed, i can't just create a new class using inheritance. I've created a new class instead:

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Schema;
using System.Xml;
using System.Xml.Serialization;
using System.Windows;
using SciChart.Charting.Visuals.Annotations;
using SciChart.Charting.Visuals.RenderableSeries;
using SciChart.Charting.Model.ChartData;
using SciChart.Charting.Visuals;

namespace ChartsDisplayer2016.Core.Charts.Models
{

    public sealed class ModifiedAxisMarkerAnnotations : ObservableCollection<IAnnotation>, IXmlSerializable
    {
        public static readonly DependencyProperty AnnotationsSourceProperty = 
            DependencyProperty.Register("AnnotationsSource", typeof(IEnumerable<SeriesInfo>), 
                typeof(ModifiedAxisMarkerAnnotations), 
                new PropertyMetadata(null, OnAnnotationsSourceChanged));

        public ISciChartSurface ParentSurface { get; set; }
        private IEnumerable<SeriesInfo> _annotationsSource;
        public IEnumerable<SeriesInfo> AnnotationsSource
        {
            get => _annotationsSource;
            set { _annotationsSource = value; RebuildAnnotations(); }
        }
        private AnnotationCollection x;
        // Get a notification when new labels are set.
        private static void OnAnnotationsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
        }

        // Recreate all annotations
        private void RebuildAnnotations()
        {
           //some stuff
        }
        public XmlSchema GetSchema()
        {
            return new XmlSchema();
        }
        public void ReadXml(XmlReader reader)
        { }
        public void WriteXml(XmlWriter writer)
        { }
    }
}

And tried to use it in xaml:

<UserControl x:Class="ChartsDisplayer2016.Core.Charts.Views.ChartUniversalView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ChartsDisplayer2016.Core.Charts.Views"
             xmlns:localmodel="clr-namespace:ChartsDisplayer2016.Core.Charts.Models"
             mc:Ignorable="d" 
             xmlns:s="http://schemas.abtsoftware.co.uk/scichart">

    <Grid Width="Auto"                            
          FocusManager.FocusedElement="{Binding ElementName=MainChartSurface}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>


        <s:SciChartSurface  RenderableSeries="{Binding RenderableSeries}"
                            YAxes="{Binding ChartYAxes, Mode=TwoWay}" >

            <!--  Here we use it  -->
            <localmodel:ModifiedAxisMarkerAnnotations AnnotationsSource="{Binding rolloverModifier.SeriesData.SeriesInfo}"/>

            <!--  Specify interactivity modifiers  -->
            <s:SciChartSurface.ChartModifier>
                <s:ModifierGroup >
                    <s:RolloverModifier Width="3" Height="3" ShowTooltipOn="MouseRightButtonDown" 
                                        Name="rolloverModifier"/>
                </s:ModifierGroup>
            </s:SciChartSurface.ChartModifier>
        </s:SciChartSurface>
    </Grid>
</UserControl>

The compiler throws an error:

Cannot add content to object of type 'SciChart.Charting.Visuals.SciChartSurface'.

How can I use my ModifiedAxisMarkerAnnotations class inside of SciChartSurface object ?

Jaroslaw Matlak
  • 574
  • 1
  • 12
  • 23

1 Answers1

0

I'm afraid what you are trying to do is not possible, as SciChartSurface.Annotations property expects type of AnnotationCollection. Since you cannot inherit AnnotationCollection then you must use the original annotation collection and not a derived type, or ObservableCollection of annotations.

What I would suggest you do instead is to create an attached property, or attached behavior, which allows you to bind to IEnumerable<SeriesInfo> and then creates annotations from the bound values, instead of overriding the collection type.

Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178