RecentDocumentManager Double Click Treated as two Single Clicks

Ribbon for WPF Forum

The latest build of this product (v22.1.4) was released 4 months ago, which was before this thread was created.
Posted 19 days ago by Rick - Developer, Visual Software Systems LLC
Version: 22.1.4
Platform: .NET 4.7
Environment: Windows 10 (64-bit)

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);

Comment out the 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 19 days ago by Actipro Software Support - Cleveland, OH, USA

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 19 days ago by Rick - Developer, Visual Software Systems LLC

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 19 days ago]

Posted 18 days ago by Actipro Software Support - Cleveland, OH, USA

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 15 days ago by Rick - Developer, Visual Software Systems LLC

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.

Add Comment

Please log in to a validated account to post comments.