Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Datagrid handling mousewheel scroll event when not focused

Sort Posts: Previous Next
  •  09-03-2008, 5:17 PM Post no. 14863

    Datagrid handling mousewheel scroll event when not focused

    I'm using the WPF DataGrid control in a DockPanel that itself is the content of a ScrollViewer (I have many WPF DataGrid controls in the DockPanel).

    The problem I'm having is the DataGrid is handling the mousewheel scroll event when it is not even focused. So when the user is scrolling with the mouse wheel  and the mouse pointer passes over a DataGrid the scrolling of the ScrollViewer stops (stalls right above the WPF DataGrid control). this artifact is annoying my users.

    Any suggestions would be appreciated

     I tried deriving my own custom datagrid to make sure the event wasn't tunneled down to the DataGrid's internal scroll viewer but it didn't work:

    public class CustomDataGridControl : Xceed.Wpf.DataGrid.DataGridControl

    {

    protected override void OnPreviewMouseWheel(MouseWheelEventArgs e)

    {

    if (this.IsFocused)

    {

    base.OnPreviewMouseWheel(e);

    }

    else

    {

    e.Handled = false;

    }

    }

    }

  •  09-04-2008, 8:47 AM Post no. 14889 in reply to 14863

    Re: Datagrid handling mousewheel scroll event when not focused

    Setting e.Handled to true rather than false should prevent the message from reaching the grid's ScrollViewer and therefore prevent it from scrolling.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  09-04-2008, 2:19 PM Post no. 14918 in reply to 14889

    Re: Datagrid handling mousewheel scroll event when not focused

    It didn't work ... The problem is somewhere in the datagrid (templete_parts?) the mouse wheel event IS being handled ... it needs to get back up to visual tree to the ScrollViewer control that holds a DockPanel which in turn holds several Xceed Datagrids and other common controls (only the Xceed grid steals the MouseWheel event).

     Thanks for your quick reply

     

  •  09-04-2008, 4:22 PM Post no. 14926 in reply to 14918

    Re: Datagrid handling mousewheel scroll event when not focused

    I have created a ticket for this issue and a developer will look into it as soon as possible. Thank you for your patience!
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  09-05-2008, 11:41 AM Post no. 14945 in reply to 14863

    Re: Datagrid handling mousewheel scroll event when not focused

    The "problem" is not with the DataGridControl, but rather with the ScrollViewer. It is not the DataGrid that handles the MouseWheel, but the ScrollViewer inside the DataGrid. You will have the same problem with a simple ListBox and I haven't found a way to prevent the ScrollViewer behaving this way. The solution, similar to what you tried, is to create your own ScrollViewer, override the OnMouseWheel and only call base when it IsFocused. Don't set the e.Handled to True, otherwise the event will stop propagating and won't reach your outermost ScrollViewer.

    Next, you need to tell the DataGrid to use this custom ScrollViewer. This is done by providing a new ControlTemplate to it, which is not necessarily obvious. You can simply copy the one provided in the XAML files installed with the product. For example:

    <xcdg:DataGridControl.Template>
      <ControlTemplate TargetType="xcdg:DataGridControl">
      <Border Background="{TemplateBinding Background}"
      BorderBrush="{TemplateBinding BorderBrush}"
      BorderThickness="{TemplateBinding BorderThickness}">
      <AdornerDecorator x:Name="PART_DragDropAdornerDecorator">
      <local:MyScrollViewer x:Name="PART_ScrollViewer"
      ShowRowSelectorPane="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.DataGridContext).ShowRowSelectorPane}"
      RowSelectorPaneWidth="{Binding RelativeSource={RelativeSource Self}, Path=(xcdg:DataGridControl.DataGridContext).RowSelectorPaneWidth}"
      Padding="{TemplateBinding Padding}">
      <xcdg:TableViewItemsHost />
      </local:MyScrollViewer>
      </AdornerDecorator>
      </Border>
      </ControlTemplate>
    </xcdg:DataGridControl.Template>

    The problem with this solution is that the FixedHeaders and FixedFooters sections of the DataGrid won't be affected because they are in their own ScrollViewer. The easiest workaround is to avoid using FixedHeaders and FixedFooters. The thorough solution is to also provide a new Template for your custom ScrollViewer based on the TableViewScrollViewer template. Again, you can find this much more intricate template in the XAML files installed with the product (TableViewScrollViewer.generic.xaml).

    The alternative to all this would be to disable the DataGridControl (IsEnabled or IsHitTestVisible), but I doubt that it would be acceptable!

  •  09-05-2008, 5:46 PM Post no. 14962 in reply to 14945

    Re: Datagrid handling mousewheel scroll event when not focused

    Thanks for the detailed explanation.

    Is there a way to access the "PART_ScrollViewer" in my derived DataGrid code so that I can access the ScrollViewer object in the CustomDataGridControl constructor and signup to it's preview mouse wheel event? I may be able to do a hack that way if what I asked above is possible.

  •  09-08-2008, 9:25 AM Post no. 14997 in reply to 14962

    Re: Datagrid handling mousewheel scroll event when not focused

    this.Template.FindName( "PART_ScrollViewer", this ) as ScrollViewer;

    But don't do it too soon! You have to wait until the template is actually applied to the DataGridControl (OnApplyTemplate, Loaded, ...).

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.