I'm new to WPF and MVVM and I started with "Jason Dolinger on Model-View-ViewModel" article and example but I have some questions regarding databinding.
1) In his demo application, he's subclassing DependencyObject for the ObservableCollection Items. What are the pros/cons compared to INotifyPropertyChanged ?
2) What is the best way to update the view from the model in a datagrid/listview ? In his example, he registers as a listener when a Quote object is added or updated :
_source.QuoteArrived += new Action<Quote>(_source_QuoteArrived);
Than the ViewModel creates and adds the QuoteViewModel object to the collection OR updates the view by setting the updated Quote object in the convenient QuoteViewModel object using a dictionary called _quoteMap.
void _source_QuoteArrived(Quote quote)
{
QuoteViewModel qvm;
if (_quoteMap.TryGetValue(quote.Symbol, out qvm))
{
qvm.Quote = quote;
}
else
{
qvm = new QuoteViewModel();
qvm.Quote = quote;
this.Quotes.Add(qvm);
_quoteMap.Add(quote.Symbol, qvm);
}
}
Is there a better way to update the view from the model when a Quote object has been updated or am I forced to create a dictionnary ? It would be so easier if the listview could be updated immediately when a Quote object is updated... without having Quote to subclass INotifyPropertyChanged or DependencyObject.
Thanks