Hi,
i am usind xamdatagrid to log data in my application.
I am using MVVm pattern and I have a observable collection of log messages.
I would like the grid to always show the last record been added in my grid.
How can I do that ?
Is there an easy way to do that in XAML only by binding RecordLastOverall command to record added event?
BR
Peter
Hello Peter,
If case you are adding the records through the UI, then you may use some of the MVVM approaches to handle this. For example you can use the attached behaviors presented in the Microsoft's Interactivity framework to associate an event (RecordAdded) to a command. If you add new items directly to the datasource, then you could execute this command from the viewmodel passing an instance of the grid as a command parameter.
Let me know if that helps.
Thank you, Vlad and Peter,
While I was waiting for your reply, I didn't realize that I could use:
SortEvaluationMode="UseCollectionView" and in my ViewModel:
ApproverEmailMessages= new ObservableCollection<SBAEmailMessage>();ApproverEmailMessagesView = CollectionViewSource.GetDefaultView(ApproverEmailMessages) as ListCollectionView; if (ApproverEmailMessagesView != null) { ApproverEmailMessagesView.SortDescriptions.Add(new SortDescription(nameof(SBAEmailMessage.ReceivedTime), ListSortDirection.Descending)); }I was skeptical that If I 'UseCollectionView' I would have to provide sort descriptions for all of 100s of fields I have but the rest of the fileds are working as usual..This is working like a charm with out compromising my MVVM and any extra behaviors.Thank you for your other suggestiuon sthough just in case If I need it.You can close the issue.