C# Xaml oxyplot HighLowSeries项目绑定
我想通过XAML定义一个C# Xaml oxyplot HighLowSeries项目绑定,c#,wpf,xaml,binding,oxyplot,C#,Wpf,Xaml,Binding,Oxyplot,我想通过XAML定义一个HighLowSeries。由于oxyplot.wpf命名空间中没有HighLowSeries图,因此我创建了以下类: public class HighLowSeries : OxyPlot.Wpf.XYAxisSeries { public HighLowSeries() { this.InternalSeries = new OxyPlot.Series.HighLowSeries(); } public over
HighLowSeries
。由于oxyplot.wpf
命名空间中没有HighLowSeries图
,因此我创建了以下类:
public class HighLowSeries : OxyPlot.Wpf.XYAxisSeries
{
public HighLowSeries()
{
this.InternalSeries = new OxyPlot.Series.HighLowSeries();
}
public override OxyPlot.Series.Series CreateModel()
{
this.SynchronizeProperties(this.InternalSeries);
return this.InternalSeries;
}
/// <summary>
/// The synchronize properties.
/// </summary>
/// <param name="series">
/// The series.
/// </param>
protected override void SynchronizeProperties(OxyPlot.Series.Series series)
{
base.SynchronizeProperties(series);
var s = (OxyPlot.Series.HighLowSeries)series;
foreach (HighLowItem item in s.Items)
{
Trace.WriteLine("HighLowSeries " + item.X);
}
}
}
在窗口的代码隐藏中,我有以下代码:
private IList<HighLowItem> _list;
public IList<HighLowItem> list
{
get
{
return this._list;
}
set
{
this._list = value;
}
}
public MainWindow()
{
this.list = new List<HighLowItem>();
list.Add(new HighLowItem(10, 8, 3, 2, 5));
list.Add(new HighLowItem(12, 7, 4, 4, 2));
list.Add(new HighLowItem(18, 4, 1, 2, 3));
this.DataContext = this;
InitializeComponent();
}
私有IList\u列表;
公共IList列表
{
得到
{
返回此。\u列表;
}
设置
{
这个。_列表=值;
}
}
公共主窗口()
{
this.list=新列表();
添加(新的HighLowItem(10,8,3,2,5));
添加(新的HighLowItem(12,7,4,4,2));
添加(新的HighLowItem(18,4,1,2,3));
this.DataContext=this;
初始化组件();
}
启动应用程序时,(0,0)处只有一条很小的水平线:
此外,在HighLowSeries.SynchronizeProperties()
中还有一个Trace.WriteLine
,我在其中打印出Items集合中HighLowElements
的X坐标。输出的数量与main窗口的list属性中的元素匹配。但X坐标始终为0(以及高下限元素的其他属性)。
当我以同样的方式实现我自己的LineSeries
时,一切都正常工作
这是oxyplot中的一个bug吗?还是我遗漏了什么?通过代码创建HighLowSeries
目前不是一个选项 终于找到了点,清除了带有数据点的列表
在源代码中(
有这样一种方法:
/// <summary>
/// Updates the data.
/// </summary>
protected internal override void UpdateData()
{
if (this.ItemsSource == null)
{
return;
}
this.items.Clear();
// Use the mapping to generate the points
if (this.Mapping != null)
{
foreach (var item in this.ItemsSource)
{
this.items.Add(this.Mapping(item));
}
return;
}
var filler = new ListFiller<HighLowItem>();
filler.Add(this.DataFieldX, (p, v) => p.X = Axis.ToDouble(v));
filler.Add(this.DataFieldHigh, (p, v) => p.High = Axis.ToDouble(v));
filler.Add(this.DataFieldLow, (p, v) => p.Low = Axis.ToDouble(v));
filler.Add(this.DataFieldOpen, (p, v) => p.Open = Axis.ToDouble(v));
filler.Add(this.DataFieldClose, (p, v) => p.Close = Axis.ToDouble(v));
filler.FillT(this.items, this.ItemsSource);
}
如果我将SynchronizeProperties
方法更改为以下内容,则一切都会正常工作
protected override void SynchronizeProperties(OxyPlot.Series.Series series)
{
base.SynchronizeProperties(series);
var s = (OxyPlot.Series.HighLowSeries)series;
s.Mapping = item => new HighLowItem(((HighLowItem)item).X, ((HighLowItem)item).High, ((HighLowItem)item).Low, ((HighLowItem)item).Open, ((HighLowItem)item).Close);
}
/// <summary>
/// Gets or sets the mapping delegate.
/// </summary>
/// <value>The mapping.</value>
/// <remarks>Example: series1.Mapping = item => new HighLowItem(((MyType)item).Time,((MyType)item).Value);</remarks>
public Func<object, HighLowItem> Mapping { get; set; }
protected override void SynchronizeProperties(OxyPlot.Series.Series series)
{
base.SynchronizeProperties(series);
var s = (OxyPlot.Series.HighLowSeries)series;
s.Mapping = item => new HighLowItem(((HighLowItem)item).X, ((HighLowItem)item).High, ((HighLowItem)item).Low, ((HighLowItem)item).Open, ((HighLowItem)item).Close);
}