我想在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
?