Stylus
Stylus

Reputation: 99

Shaping ObservableCollection

I have a really simple question.

I got an ObservableCollection of some ViewModel (with INotifyPropertyChanged) which gets updated frequently.

Now I need to shape the data into a new ObservableCollection of NewViewModel like this;

        var query = from o in _orders
                select new ComplexRowViewModel()
                           {Isin = o.Isin,
                            Name = o.Isin,
                            GermanSymbol = o.Exchange,
                            PrimarySymbol = o.State.ToString()};
        GridData = query;

But of course it doesn't work. Just if I use Obtics or CLINQ, the new collection gets updated if a new item comes into the first collection but if an existing item's properties change, it doesn't get updated in the new collection.

So any ideas?

Upvotes: 1

Views: 173

Answers (3)

Igor Buchelnikov
Igor Buchelnikov

Reputation: 565

You can also try my ObservableComputations library. Using that library:

        var query = _orders.Selecting(o => 
                new ComplexRowViewModel()
                           {Isin = o.Isin,
                            Name = o.Isin,
                            GermanSymbol = o.Exchange,
                            PrimarySymbol = o.State.ToString()};
        GridData = query;

To make code above working _orders should be of type ObservableCollection and Order class (I suggest it is type of elements in _orders ObservableCollection) should implement INotifyPropertyChanged.

Upvotes: 0

SMB-BO
SMB-BO

Reputation: 36

I don't know Obtics or CLINQ but it sounds like the normal behaviour of the ObservableCollection. It's not reacting on property changes of the single items it contains at all. So you have to write your own implementation of the ObservableCollection. One example is shown here: ObservableCollection that also monitors changes on the elements in collection

Upvotes: 1

Felice Pollano
Felice Pollano

Reputation: 33272

You should implement INotifyPropertyChange from NewViewModel too. In each of this subscibe the INotifyPropertychange on the source order and raise a new event properly.

Upvotes: 0

Related Questions