One of my customers reported that sometimes two files are opened when using the Recent Documents list. I found that this occurs when double clicking on a recent document link. TheRecentDocumentManager calls the Open command twice. You can see this behavior in the Sample project by making the following simple change in the fileOpenCommand_Execute method in ProductSamples.RibbonSamples.Demo.DocumentEditor.MainWindow:
private void fileOpenCommand_Execute(object sender, ExecutedRoutedEventArgs e) {
if (e.Parameter is IDocumentReference) {
// Process recent document clicks
Debug.WriteLine("Opening " + ((IDocumentReference)e.Parameter).Name);
//MessageBox.Show("Open document '" + ((IDocumentReference)e.Parameter).Name + "' here.", "Open Recent Document", MessageBoxButton.OK, MessageBoxImage.Information);
recentDocManager.NotifyDocumentOpened(((IDocumentReference)e.Parameter).Location);
return;
}
Comment out the MessageBox.show line and add the line above it. You'll see in the console that the open method is called twice for any file that gets double-clicked. It's a little worse if using the NotifyDocumentOpened method to update the recent document list. If you add the line after the MessageBox.Show, what you'll see in the console is that the file that was double-clicked is opened as well as either the file above or below it in the recents list. This is becuase the position of the document moves when NotifyDocumentOpen is called so the second click of the double-click gets associated with whatever document is then under the mouse pointer.