【发布时间】:2015-02-09 16:03:42
【问题描述】:
我想通过 XAML 定义一个HighLowSeries。由于HighLowSeries-graphs 在oxyplot.wpf 命名空间中不可用,我创建了以下类:
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);
}
}
}
在我的窗口中,我通过以下方式使用HighLowSeries:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Oxy="http://oxyplot.org/wpf"
xmlns:Tmp="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Oxy:PlotView Width="300"
Height="300"
Title="Test">
<Oxy:PlotView.Series>
<Tmp:HighLowSeries ItemsSource="{Binding list}" />
</Oxy:PlotView.Series>
</Oxy:PlotView>
</Grid>
</Window>
在Window后面的代码中,我有以下代码:
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();
}
当我启动应用程序时,在 (0,0) 处只有一条很小的水平线:
此外,HighLowSeries.SynchronizeProperties() 中还有一个 Trace.WriteLine,我在其中打印出 Items-Collection 中 HighLowElements 的 X 坐标。输出的数量与MainWindow 的列表属性中的元素相匹配。但 X 坐标始终为 0(以及 HighLowElements 的其他属性)。
当我以同样的方式实现自己的LineSeries 时,一切正常。
这是 oxyplot 中的错误吗?还是我错过了什么?目前无法通过代码创建HighLowSeries。
【问题讨论】:
标签: c# wpf xaml binding oxyplot