More information about Recent Files
WorkingFileManager takes care of recent files mostly automatically. When you successfully open or save a file, that file gets placed on the top of the recent files list. If you try to open a file but fail, it will be removed from the recent files list if it is already present.

WorkingFileManager does not persist the recent files list across sessions with your application. You must provide code to save the list before your program closes and to reload it when your application starts. You may also want to record the recent files as soon as they change, rather than waiting for the application to close, so they will remain up to date even if the application crashes.

A good place to load your recent files list from your persistence logic is in your MainWindowViewModel constructor. There, you can do something like this:
_workingFileState.AddToRecentFiles(Config.Current.RecentFileFromPersistence4);
_workingFileState.AddToRecentFiles(Config.Current.RecentFileFromPersistence3);
_workingFileState.AddToRecentFiles(Config.Current.RecentFileFromPersistence2);
_workingFileState.AddToRecentFiles(Config.Current.RecentFileFromPersistence1);
Note that recent files are inserted at the top of the list, so we insert them in reverse order.

To catch changes to the list of recent files, you can add an event handler like this:
((INotifyCollectionChanged)_workingFileState.RecentFiles).CollectionChanged += (s, e) =>
{
   //save recent files list to persistence
}

The number of recent files displayed in the menu is currently limited to 4. You could modify this in the WorkingFileManager code. It may be made into a more easily customized property in the future.

Last edited Aug 5, 2012 at 3:22 PM by jmtonn, version 3

Comments

No comments yet.