SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

0
0

I am using SciChart MVVM and need to bind to the stroke property of the type LineRenderableSeriesViewModel. Is there anyway to make this happen? It doesn’t support binding as follows:

LineRenderableSeriesViewModel renderSeries = new LineRenderableSeriesViewModel();
Binding b1 = new Binding();
b1.Source = this;
b1.Path = new PropertyPath("color");
BindingOperations.SetBinding(renderSeries, BaseRenderableSeries.StrokeProperty, b1);

I cannot find a way to expose the properties of the LineRenderableSeriesViewModel (IRenderableSeriesViewModel).

Version
5.3.0.11969
  • Oleksandr Shvets
    Hi Robert, Thanks for your question. The MVVM API isn’t intended to work in this way. In WPF, you can set Bindings on objects that derive from the DependencyObject type. This is what all UIElements do. As to ViewModels, they are supposed to implement INotifyPropertyChanged in order to act as a source of Binding, not a destination. So you can not do it like this. Please try to change it on your side and let us know if you have any further questions.
  • You must to post comments
0
0

Thank you for the comment Oleksandr. I am constrained by the MVVM principles and need a dynamic number of renderableseries and am not sure what you are suggesting I change. The only way I see I can bind a dynamic number of FastLineRenderableSeries to Scichart is as follows:

RenderableSeries="{s:SeriesBinding RenderableSeriesModel}" 

With “RenderableSeriesModel” being an observablecollection of IRenderableSeriesViewModel and built as follows:

    public ObservableCollection<IRenderableSeriesViewModel> RenderableSeriesModel { get; set; }
    //in some method   
    for (int i = 0; i < SomeNumber; i++)
    {
            var renderSeries = new LineRenderableSeriesViewModel
            {
                IsVisible = false,
                YAxisId = "yAxis"
            };
            RenderableSeriesModel.Add(fl.renderSeries);
    }

If the API supported an observablecollection of type “FastLineRenderableSeries” instead of “LineRenderableSeriesViewModel” then there would be no binding limitation. Am I missing something?

Anyway, I just implemented a wrapper class to allow for binding to properties to solve my problem:

class FastLineWrapper : DependencyObject
{
    public Color? Stroke
    {
        get
        {
            return (Color)GetValue(StrokeProperty);
        }
        set
        {
            SetValue(StrokeProperty, value);
        }

    }

    public LineRenderableSeriesViewModel renderSeries = new LineRenderableSeriesViewModel();

    public static readonly DependencyProperty StrokeProperty =
        DependencyProperty.Register("Stroke", typeof(Color?), typeof(FastLineWrapper), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnPropChanged)));

    public static void OnPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        FastLineWrapper ui = d as FastLineWrapper;
        if (ui != null)
        {
            ui.renderSeries.Stroke = (Color?)e.NewValue;
        }
    }

}
  • You must to post comments
0
0

Hi Robert,

Thanks for your reply.

SeriesBinding is a part of our MVVM API that has been added to SciChart not that long ago. Besides it, there is another way of adding series onto a chart directly, via creation of RenderableSeries objects. If you take a look at our documentation about the RenderableSeries property, you will see that it is declared exactly as you want it to – as ObservableCollection.

This is also described in our Tutorials that describe both approaches, the MVVM one and the code-behind one.

So feel free to choose the one which works better for you. In case of creating RenderableSeries directly and binding them to SciChartSurface you don’t need to wrap them in another class. RenderableSeries can also be bound to, unlike RenderableSeriesViewModels.

Hope this helps,

Best Regards,
Yuriy

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.