private void ItemsControl_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { try { //foreach (var game in ViewModel.FilteredGames) // game.ViewModel.SetDestination(game.ViewModel.X, game.ViewModel.Y + e.Delta); //foreach (var game in ViewModel.FilteredGames) // game.MoveToDestination(1); e.Handled = true; //var gameGrid = Helpers.UIHelper.FindChild<Grid>(GameGridScrollViewer, "GameGrid"); //var realScrollableHeight = ((gameGrid.RowDefinitions.Count - 1) / 2) * (Const.GameControlSize.Height + Const.GridBorder) - GameGridScrollViewer.ViewportHeight; // TODO BUG max scrolling height is not updated after filter change // TODO scrolling with pgUp/ pgDown or ctrl+pgUp / pgDown should be checked against realScrollableHeight // "smooth" scrolling Threading.ThreadAndForget(() => { var direction = e.Delta < 0 ? -1.0 : 1.0; for (var scrollStep = Math.Abs((double)e.Delta); scrollStep > 1; scrollStep = scrollStep / 2) { var newScroll = /*Math.Min(*/ GamesScrollViewer.VerticalOffset - (scrollStep * direction); //, realScrollableHeight); GamesScrollViewer.Dispatcher.Invoke(() => { GamesScrollViewer.ScrollToVerticalOffset(newScroll); }); //if (newScroll == realScrollableHeight) // break; System.Threading.Thread.Sleep(16); } }); } catch (Exception ex) { Log.WriteLine(ex.ToString()); } }
private void FilterButton_Click(object sender, RoutedEventArgs e) { // reset scroll to zero when filter is changed GamesScrollViewer.ScrollToVerticalOffset(0); }