Is there a way, to bind the series of a OxyPlot in XAML, if I don't know, how many series I will have?
I know, that I can create a PlotModel, maybe I can bind a Collection of Series. But what I am realy looking for is, if I can bind the series to List of doubles.
Possible ItemSources examples:
ObservableCollection<Tupel<double, List<double>>> ItemSource1 { get; set; }
ObservableCollection<Tupel<double, double>> ItemSource2 { get; set; }
Possible Xaml Code:
<oxy:Plot>
<oxy:LineSeries ItemSource="{Binding ItemSource}" />
</oxy:Plot>
I dind't find such a use case in the examples. Does someone have maybe a tipp for me?
Is there a way, to bind the series of a OxyPlot in XAML, if I don't know, how many series I will have?
No, there isn't.
Does someone have maybe a tipp for me?
As you have already discovered, you could create a PlotModel
in your view model, and bind to and add series to this one.
There is a code sample available in 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}"/>
If you don't want to use a PlotModel
, you could create an attached behaviour that adds the series.