RecentDocumentManager Double Click Treated as two Single Clicks

Ribbon for WPF Forum

Posted 1 year ago by Rick - Developer, Visual Software Systems LLC
Version: 22.1.4
Platform: .NET 4.7
Environment: Windows 10 (64-bit)
Avatar

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.

Comments (4)

Answer - Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rick,

I tried to duplicate it with the code above, but was unable to.

Regardless, that is somewhat expected behavior and should be the same with any Button.  If you double-click a button, it will effectively fire the command twice, once for each click.  The recent document list control uses buttons for its items.

In the recent document control scenario we clearly don't want two commands to fire though, for all the reasons you listed.  The best way to prevent it is to ensure the recent document control is hidden after the first click (when the command fires).  You could set Ribbon.IsApplicationMenuOpen = false to hide it.  Then the second click will never get through to it.


Actipro Software Support

Posted 1 year ago by Rick - Developer, Visual Software Systems LLC
Avatar

Curious that you couldn't replicate the behavior using the code I supplied.  I tried what you suggested - adding Ribbon.IsApplicationMenuOpen = false. I put it in the RecentDocumentMenu's PreviewMouseDoubleClick event handler and that did mitigate the issue.  I'd much rather the second click get blocked natively in the RecentDocumentsManager rather than in application code becasue, as you agreed, this is undesireable behavior and as such it's reasonable to expect the control to handle that.

[Modified 1 year ago]

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Glad to hear closing the menu mitigated the issue, and we respect your perspective on the double-click handling. Since the current behavior is based on how WPF Button's and their associated Command is processed, we would have to significantly restructure the implementation to further mitigate the double-click concern.

Please let us know if there is a scenario you are trying to support where you leave the app menu open after selecting a recent document.


Actipro Software Support

Posted 1 year ago by Rick - Developer, Visual Software Systems LLC
Avatar

No, there are no other scenarios that I'm trying to support.  The solution you provided provided works perfectly, so I'm good.  Thanks for taking another look at it.

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.