A
A
Arseniy2014-04-26 07:53:13
WPF
Arseniy, 2014-04-26 07:53:13

How to bind a ListView to a collection that is in another class

The bottom line is this:
There is a class that processes the graphical interface (it is created by itself). There is a second class that listens on the port and captures some of the data that came to it ... I would display this data in the 1st class in the ListView as it arrives .... That is, what I need came to the socket and I brought it to the ListView. Please tell me how to implement it.
PS C#, WPF

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Miraemor, 2014-04-27
@Trytge

Make an event in the second class, for example NewDataRecieved, and the first class subscribe to this event. When the second class receives the data, it will fire an event and all subscribers can process it, the first class, for example, will add it to its ListView.
Or, in the second class, implement the INotifyPropertyChanged interface and make a public field with a list of data. In the first class, it's easy to set the binding to the list from the second class. In this case, when the second class adds new elements to its list, the first class will update the binding automatically.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question