Can't programmatically binding to OxyPlot properties

Mar 24, 2014 at 11:18 PM
I want to create a databinding programmatically for the LineSeries.Color property. The LineSeries.Color property must be a dependency property because you can bind to it in XAML. However, if I want to create a binding dynamically in code-behind, I need the static property LineSeries.ColorProperty. For example, the WPF TextBox.Text has an analogous TextBox.TextProperty. But Intellisense shows no LineSeries.ColorProperty.
Mar 25, 2014 at 7:58 PM
See OxyPlot.Wpf.Series.ColorProperty. It is public and the type is System.Windows.Media.Color
Mar 26, 2014 at 6:35 PM
thanks for your quick reply. I tried your solution and in order to get it to work we must use OxyPlot.Wpf.LineSeries (because it a DependencyObject and that is required for DataBinding). I used the following code:
            var ls = new OxyPlot.Wpf.LineSeries();
            var b = new Binding();
            b.Source = mySourceObject;
            b.Path = new PropertyPath("Color");           
            b.Mode = BindingMode.TwoWay;
            ls.SetBinding(OxyPlot.Wpf.Series.ColorProperty, b);

This code compiles perfectly but when I try to add the LineSeries to the model it won't compile:
           PlotModel model
I get an error telling me that "ls" is the wrong type. It is expecting the non-WPF LineSeries. I have looked for a WPF version of PlotModel but can't find any. Thanks for you help.
Mar 26, 2014 at 7:55 PM
No, you cannot add a OxyPlot.Wpf.LineSeries to the OxyPlot.PlotModel. Try adding the "ls" to the Series collection in your OxyPlot.Wpf.Plot control.