Click here to Skip to main content
15,947,958 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to plot graph for different objects on canvas in the view. Can I use PointCollection for storing the points for different objects. And make a property of type PointCollection. Then in xaml I will bind the line to this PointCollection property.

What I have tried:

I just need to know is it possible or not.
Updated 15-Nov-18 18:55pm
Richard MacCutchan 15-Nov-18 8:57am    
You could find out whether it is possible by trying it in a test program.
hamid18 15-Nov-18 9:02am    
I am new to mvvm and wpf. So I am not sure whether we can use PointCollection in Viewmodel or not. Because in mvvm we cannot use any View Control.
#realJSOP 15-Nov-18 12:25pm    
He said try it and see. "Can I do this" is a STUPID question for a developer. Why? Because it solidly demonstrates a lack of initiative, or even the ability to google how to do something. Devs today have MUCH FREE access to more extensive resources than we did back in the days before google, yet they refuse to use those tools. I mourn for the software industry as a whole. Good luck in whatever vocation you end up with, because it won't be software development if you can't find/develop the skill to use google.
hamid18 19-Nov-18 8:12am    
sorry.. i am trying to learn.. i do not post question without searching it on google. i am a newbie in programming. because of lack of experience sometimes i happens that i do not understand on the internet. i will be careful in future..

1 solution

Best place to check is in the documentation: PointCollection Class (System.Windows.Media) | Microsoft Docs[^]

If you're looking a using the MVVM Design Pattern, then you're looking at using Data Binding (WPF) | Microsoft Docs[^] . For Data Binding to work with XAML, you need to hook into the data binding notification syste. Looking at the PointCollection code from the link above, it does not do this:
public sealed class PointCollection : System.Windows.Freezable, IFormattable, System.Collections.Generic.ICollection<System.Windows.Point>, System.Collections.Generic.IEnumerable<System.Windows.Point>, System.Collections.Generic.IList<System.Windows.Point>, System.Collections.IList

What you need to do is write a Proxy class wrapper for the PointCollection class that implements both the System.Collections.Specialized.INotifyCollectionChangedand System.ComponentModel.INotifyPropertyChanged interfaces for Data Binding to work properly.

To see an example of this, take a look at the data binding collection ObservableCollection<T> Class (System.Collections.ObjectModel)[^].
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900