Can't programmatically binding to OxyPlot properties

Oystein Bjorke 6 years ago 0
This discussion was imported from CodePlex

richardfen wrote at 2014-03-25 00:18:

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.

objo wrote at 2014-03-25 20:58:

See OxyPlot.Wpf.Series.ColorProperty. It is public and the type is System.Windows.Media.Color

richardfen wrote at 2014-03-26 19:35:

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.

objo wrote at 2014-03-26 20:55:

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.