0
votes

We’re developing an application in WPF, programming with low code-behind. We’re using a lot of MVVM and Binding resources. I’ve searched the web , trying to find a way to make a Double-Click on a grid without code-behind and we’ve found the AttachedCommandBehavior project (http://marlongrech.wordpress.com/2008/12/13/attachedcommandbehavior-v2-aka-acb/), but we're getting an unexpected issue:

When user click into the DataGrid, works ok, but the Mouse_Double_Click shouldn’t be fired when clicking on Columns Header or ScrollViewer. So, how we can fix it? We need than the AttachedCommandBehavior fires the event when user clicks only inside DataGrid’s area. I’ve downloaded your source, to see if he gets what object is being click, but i didn’t found it.

Best regards!

1
instead of applying it on the entire grid, put it on only the grid area - Jake Berger
Doesn't work, already tried that. Do you have an example to how make it work? - Gustavo Gonçalves
I forgot to say something: We have datagrids with more than 60 columns, which makes it infeasible to do, column by column. - Gustavo Gonçalves
use an attached property on the DataGrid which loops through its columns - Jake Berger

1 Answers

0
votes

This is how we've resolved the problem: We've created a UserControl component as a DataGrid, and into his code-behind, added this:

  private void dtgExtended_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        if (sender is Control
            && (!e.OriginalSource.ToString().Equals("Microsoft.Windows.Themes.ScrollChrome") && !e.OriginalSource.ToString().Equals("System.Windows.Shapes.Rectangle")))
        {
            e.Handled = false;
            DataGridDoubleClick c = new DataGridDoubleClick();
        }
        else
            e.Handled = true;
    }

Basically, this only identifies if user clicks inside the rectangle of the area of the ScrollBar, or the ScrollBar. It doesn't identifies if has any click into the header of the column.

But solved my problem, at last.