Can't programmatically binding to OxyPlot properties

Mar 25, 2014 at 12:18 AM
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.
Coordinator
Mar 25, 2014 at 8:58 PM
See OxyPlot.Wpf.Series.ColorProperty. It is public and the type is System.Windows.Media.Color
Mar 26, 2014 at 7: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
           model.Series.Add(ls)
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.
Coordinator
Mar 26, 2014 at 8: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.