Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

WPF binding to object

Solved!
Go to solution

Hi

I would like to bind an object collection to my Graph. The binding should be dynamic, thats is, when I add an object to the collection the graph should be updated accordingly.

 

I have attached a code example. Questions:
1. Is there a way to map my properties (flow,head) to x/y coordinates. When I run the code the execution stops at sg.DataSource=olist

2. I will have many plots in the graph. How do I bind a collection to a certain plot?

3. Could i use a "list(of PLCResponse)" instead of an ObservableCollection. Whats the best approach here?

 

Thanks

/Axel

Sweden

0 Kudos
Message 1 of 5
(6,036 Views)

1) For the graph to recognize your custom data type, you need to implement descriptor for that type. In this case, one that implements the IOpMultiDimensional interface, like the attached PLCResponseDescriptor.vb file.*


2) To supply data to a particular plot, you can either use the Data collection directly (e.g. sg.Data(0) = olist0 to give data to the first plot, sg.Data(1) = olist1 for the second plot, etc); or use a data source containing multiple collections (e.g. sg.DataSource = { olist0, olist1, ... }).


3) Using an observable collection is the simplest way to get the graph to re-draw when PLC items are added or removed. Using a list or other collection would also work, but the graph will not automatically respond when the list is modified; instead, you would need to manually call Refresh, or assign a new collection, for the graph to re-draw.



* – Measurement Studio does not currently support Decimal values natively, so the descriptor converts the data into double values for display by the graph.


– The graph will only respond to changes to the collection itself, not to changes on the items in the collection (e.g. olist(0).Head = 1 will not cause the graph to re-draw). If you want the graph to automatically respond to item-level changes, you would want to implement an IOpObservable descriptor for your OPoints collection type, raising an event for both collection and item changes.

~ Paul H
0 Kudos
Message 2 of 5
(6,018 Views)
Solution
Accepted by topic author AxelHaraldsson

Thanks Paul. The descriptor works fine Smiley Happy

 

I also tried to implement an IOpObservable descriptor but I could not make it work. Are both the descriptors required to make the Graph react on changes in my items?

You are also mentioning that I must raise an event. Do I have to implement this or is it performed by ValueObserver in some way?

 

I could not find any examples with this descriptor when searching the DotNet\Examples folder....

 

Regards

Axel

 

0 Kudos
Message 3 of 5
(5,970 Views)

Implementing custom descriptors is a more advanced topic, and we have not created any examples for it yet.

 

For IOpObservable(Of OPoints) in particular, the idea is to:
 

  1. Move the implementation of the GetDimensionDataTypes/DecomposeValues/etc methods on the example PLCResponseDescriptor to the GetDimensionDataTypes/Decompose/etc methods on a new OPointsDescriptor, and
     
  2. Implement GetValueObserver, which would monitor a particular OPoints instance through CollectionChanged, as well as every PLCResponse in the collection through PropertyChanged.

(The ObservedValueChanged event on IValueObserver was the event I was referring to earlier.)

~ Paul H
0 Kudos
Message 4 of 5
(5,961 Views)

Thanks. I will try this again.

/Axel

0 Kudos
Message 5 of 5
(5,952 Views)