Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1886
CodeBehind Databinding for Series.Title
posted

I have an app that we are adding multiple series' to a ScatterLineSeries in the code behind when our VM is either added to or removed from.  Also, our VM contains the "Series Name' that is editable in another portion of the UI.  I have everything wired up and working EXCEPT automatic changing of the series name in the legend when our Observable Collection is changed. 

My ViewModel is similar to this

 

Public ObservableCollection<ScatterPointCollection> DataSerieses

public class ScatterPointCollection : ObservableCollection<ScatterPointData>, INotifyPropertyChanged

{

   public string XField {get; set; }

   public string XField {get; set; }

   public string SeriesTitle { get; set; }

  ...

}

 

then in code behind, whenever I add a series I loop through the 'DataSerieses' collection and create a new ScatterLineSeries...

loop

   ...

    ScatterLineSeries sls = new ScatterLineSeries();

   ...

   sls.Title = dataSeries.SeriesTitle;

   ...

end loop

This provides me with the correct title in the legend initially, BUT, if I change the dataSeries.Title, it is not reflected in the legend until the chart is redrawn.  I realize this is because I have not properly bound the slc.Title to the DataSeries properly, but there is no "SetBinding()" method available on the slc.Title property - it isjust type object.

How can I do this binding in code behind?  I had it working in XAML, but in order to handle multiple series' I need to do it in code behind!

thanks

Rod

Parents
No Data
Reply
  • 1886
    Verified Answer
    posted

    Sorry about the post, but in one last ditch effort to fix the issue - the solution slapped me in the face.  in the above code snippet, substitute the following, and everything works

     

    TextBlock  txtbl = new TextBlock();

    txtbl.DataContext = DataSeries;

    txtbl.SetBinding( TextBlock.TextProperty, new Binding("SeriesTitle") );

    sls.Title = txtbl;

     

Children