Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF DataGrid auto-scrolls horizontally on cell click hiding the beginning of text #19

Open
KirillOsenkov opened this issue Jul 17, 2020 · 4 comments
Labels

Comments

@KirillOsenkov
Copy link
Owner

https://www.codeproject.com/Tips/5165488/Prevent-WPF-DataGrid-Auto-scrolling-Due-to-Clickin

@KirillOsenkov
Copy link
Owner Author

Related: #13

Stack:

  | PresentationFramework | RequestBringIntoViewEventArgs.InvokeEventHandler Line 53
-- | -- | --
  | PresentationCore | RoutedEventArgs.InvokeHandler Line 336
  | PresentationCore | RoutedEventHandlerInfo.InvokeHandler Line 84
  | PresentationCore | EventRoute.InvokeHandlersImpl Line 207
  | PresentationCore | UIElement.RaiseEventImpl Line 2340
  | PresentationCore | UIElement.RaiseEvent Line 420
  | PresentationFramework | FrameworkElement.BringIntoView Line 3314
  | PresentationFramework | FrameworkElement.OnGotFocus Line 5401
  | PresentationCore | UIElement.IsFocused_Changed Line 3558
  | WindowsBase | DependencyObject.OnPropertyChanged Line 2082
  | PresentationFramework | FrameworkElement.OnPropertyChanged Line 2076
  | WindowsBase | DependencyObject.NotifyPropertyChange Line 1757
  | WindowsBase | DependencyObject.UpdateEffectiveValue Line 1571
  | WindowsBase | DependencyObject.SetValueCommon Line 851
  | WindowsBase | DependencyObject.SetValue Line 594
  | PresentationCore | FocusManager.OnFocusedElementChanged Line 248
  | WindowsBase | DependencyObject.OnPropertyChanged Line 2082
  | PresentationFramework | FrameworkElement.OnPropertyChanged Line 2076
  | WindowsBase | DependencyObject.NotifyPropertyChange Line 1757
  | WindowsBase | DependencyObject.UpdateEffectiveValue Line 1571
  | WindowsBase | DependencyObject.SetValueCommon Line 851
  | WindowsBase | DependencyObject.SetValue Line 432
  | PresentationCore | FocusManager.SetFocusedElement Line 180
  | PresentationFramework | KeyboardNavigation.UpdateFocusedElement Line 962
  | PresentationFramework | FrameworkElement.OnGotKeyboardFocus Line 5370
  | PresentationCore | KeyboardFocusChangedEventArgs.InvokeEventHandler Line 76
  | PresentationCore | RoutedEventArgs.InvokeHandler Line 336
  | PresentationCore | RoutedEventHandlerInfo.InvokeHandler Line 84
  | PresentationCore | EventRoute.InvokeHandlersImpl Line 207
  | PresentationCore | UIElement.RaiseEventImpl Line 2340
  | PresentationCore | UIElement.RaiseTrustedEvent Line 457
  | PresentationCore | InputManager.ProcessStagingArea Line 829
  | PresentationCore | InputManager.ProcessInput Line 575
  | PresentationCore | KeyboardDevice.ChangeFocus Line 508
  | PresentationCore | KeyboardDevice.TryChangeFocus Line 405
  | PresentationCore | KeyboardDevice.Focus Line 197
  | PresentationCore | KeyboardDevice.Focus Line 163
  | PresentationCore | UIElement.Focus Line 2616
  | PresentationFramework | DataGridCell.OnAnyMouseLeftButtonDown Line 929
  | PresentationFramework | DataGridCell.OnAnyMouseLeftButtonDownThunk Line 891
  | PresentationCore | MouseButtonEventArgs.InvokeEventHandler Line 130
  | PresentationCore | RoutedEventArgs.InvokeHandler Line 336
  | PresentationCore | RoutedEventHandlerInfo.InvokeHandler Line 84
  | PresentationCore | EventRoute.InvokeHandlersImpl Line 207
  | PresentationCore | UIElement.ReRaiseEventAs Line 2289
  | PresentationCore | UIElement.OnMouseDownThunk Line 923
  | PresentationCore | MouseButtonEventArgs.InvokeEventHandler Line 130
  | PresentationCore | RoutedEventArgs.InvokeHandler Line 336
  | PresentationCore | RoutedEventHandlerInfo.InvokeHandler Line 84
  | PresentationCore | EventRoute.InvokeHandlersImpl Line 207
  | PresentationCore | UIElement.RaiseEventImpl Line 2340
  | PresentationCore | UIElement.RaiseTrustedEvent Line 457
  | PresentationCore | InputManager.ProcessStagingArea Line 829
  | PresentationCore | InputManager.ProcessInput Line 575
  | PresentationCore | InputProviderSite.ReportInput Line 106
  | PresentationCore | HwndMouseInputProvider.ReportInput Line 1298
  | PresentationCore | HwndMouseInputProvider.FilterMessage Line 508
  | PresentationCore | HwndSource.InputFilterMessage Line 1577
  | WindowsBase | HwndWrapper.WndProc Line 295
  | WindowsBase | HwndSubclass.DispatcherCallbackOperation Line 429
  | WindowsBase | ExceptionWrapper.InternalRealCall Line 103
  | WindowsBase | ExceptionWrapper.TryCatchWhen Line 36
  | WindowsBase | Dispatcher.LegacyInvokeImpl Line 1331
  | WindowsBase | HwndSubclass.SubclassWndProc Line 341
  |   | [IL Method without Metadata]
  |   | [Internal Frame, 'M-->U']
  | WindowsBase | Dispatcher.PushFrameImpl Line 2137
  | WindowsBase | Dispatcher.PushFrame Line 331
  | WindowsBase | Dispatcher.Run Line 299
  | PresentationFramework | Application.RunDispatcher Line 2403
  | PresentationFramework | Application.RunInternal Line 1694
  | PresentationFramework | Application.Run Line 198
  | wpf | App.Main

@KirillOsenkov
Copy link
Owner Author

@KirillOsenkov
Copy link
Owner Author

Workaround:

            var style = new Style();
            style.Setters.Add(new EventSetter(FrameworkElement.RequestBringIntoViewEvent, (RequestBringIntoViewEventHandler)OnRequestBringIntoView));
            dataGrid.ItemContainerStyle = style;

            void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
            {
                if (e.OriginalSource is DataGridCell && e.TargetRect == Rect.Empty)
                {
                    e.Handled = true;
                }
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant