有没有办法,在XAML中绑定一系列OxyPlot,如果我不知道,我会有多少系列?
我知道,我可以创建一个PlotModel,也许我可以绑定一个Collection系列。但我真正想要的是,如果我可以将系列绑定到双打列表。
可能的ItemSources示例:
ObservableCollection<Tupel<double, List<double>>> ItemSource1 { get; set; }
ObservableCollection<Tupel<double, double>> ItemSource2 { get; set; }
可能的Xaml代码:
<oxy:Plot>
<oxy:LineSeries ItemSource="{Binding ItemSource}" />
</oxy:Plot>
我在示例中找不到这样的用例。有人可能会给我一个tipp吗?
有没有办法,在XAML中绑定一系列OxyPlot,如果我不知道,我会有多少系列?
不,没有。
有人可能会给我一个tipp吗?
正如您已经发现的那样,您可以在视图模型中创建PlotModel
,并绑定并添加到此视图模型中。
the official docs中提供了一个代码示例:
public class MainViewModel
{
public MainViewModel()
{
this.MyModel = new PlotModel { Title = "Example 1" };
this.MyModel.Series.Add(new FunctionSeries(Math.Cos, 0, 10, 0.1, "cos(x)"));
}
public PlotModel MyModel { get; private set; }
}
XAML:
<oxy:PlotView Model="{Binding MyModel}"/>
如果你不想使用PlotModel
,你可以创建一个添加系列的attached behaviour。