0

我想在AnnotationCollection类中添加一个参数。因为它是sealed,我不能只使用继承创建一个新类。我创建了一个新类:

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)
        { }
    }
}

并尝试将其用于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>

编译器抛出错误:

无法向“SciChart.Charting.Visuals.SciChartSurface”类型的对象添加内容。

如何ModifiedAxisMarkerAnnotations在 object 中使用我的类SciChartSurface

4

1 回答 1

0

恐怕您尝试做的事情是不可能的,因为SciChartSurface.Annotations属性需要AnnotationCollection类型。由于您不能继承 AnnotationCollection,因此您必须使用原始注释集合而不是派生类型或注释的 ObservableCollection。

我建议您改为创建一个附加属性或附加行为,它允许您绑定到IEnumerable<SeriesInfo>然后从绑定值创建注释,而不是覆盖集合类型。

于 2017-04-24T15:22:24.577 回答