简体   繁体   中英

Having trouble binding data from C# to WPF to draw a line graph

Code Behind - I have an Observable Collection of Points which holds data to plot to the graph. This data is read from an external source and will have anything from 20k-80k thousands values in each of these lists.

ObservableCollection<System.Windows.Point> listChannelData =new ObservableCollection <System.Windows.Point>();
ObservableCollection<System.Windows.Point> listActiveBaseline =new ObservableCollection <System.Windows.Point>();

Once these lists are populated, I then set the series ItemSource to these lists like so:

seriesChannelData.ItemsSource = listChannelData;
seriesActiveBaseline.ItemsSource = listActiveBaseline;

XAML - Not sure if the XAML is correct as just started learning, I also don't know if it's better to bind to the Observable Collection in the code or in the XAML.

<DVC:LineSeries Name="seriesChannelData" DependentValuePath="Y" IndependentValuePath="X" ItemsSource="{Binding seriesChannelData}" IsSelectionEnabled="True"/>
<DVC:LineSeries Name="seriesActiveBaseline" DependentValuePath="Y" IndependentValuePath="X" ItemsSource="{Binding}" IsSelectionEnabled="True" />

When I try to run this program it seems to take a long time to populate the lists and nothing charts, so it seems my data binding is wrong. Another thing I would like to find out is if I am wrong in setting the series item source to the lists after they have been populated.

Any help is appreciated, just started with WPF and trying to learn about a lot of things at once here. Thank you.

<DVC:Chart Name="seriesChannelData" VerticalAlignment="Top" Height="200"
DataContext="{Binding seriesChannelData}" IsTabStop="True" Background="White">
<DVC:LineSeries DependentValuePath="Y" IndependentValuePath="X"
ItemsSource="{Binding}">
</DVC:LineSeries>
</DVC:Chart>

In the DataContext you will bind the observable collection Name and in the Dependent ValuePath and IndependentValuePath you bind the members of the observable collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM