private void ListView_Loaded(object sender, RoutedEventArgs e)
        {
            ListView     listView = (ListView)sender;
            ScrollViewer scroll   = VisualTreeHelperEx.FindDescendantByType <ScrollViewer>(listView);

            if (scroll == null)
            {
                return;
            }

            // 鼠标横向滚动。
            listView.AddHandler(MouseWheelEvent, new MouseWheelEventHandler((mouseWheelSender, mouseWheelEventArgs) =>
            {
                var delta = mouseWheelEventArgs.Delta;
                if (delta > 0)
                {
                    scroll.LineLeft();
                }
                else
                {
                    scroll.LineRight();
                }
            }), true);


            var bar = scroll.FindVisualChildren <ScrollBar>().ElementAt(2);

            bar.ValueChanged += bar_ValueChanged;
            _bottomBar        = bar;
        }
Пример #2
0
        /// <summary>
        /// Scroll to the bottom when a new item has been logged, if it was previously scrolled all the way down
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            var viewer = VisualTreeHelperEx.FindDescendantByType <ScrollViewer>(this.listViewEvents);

            if (viewer != null)
            {
                // User scroll event : set or unset auto-scroll mode
                if (e.ExtentHeightChange.Equals(0))

                {
                    // Content unchanged : user scroll event
                    if (viewer.VerticalOffset.Equals(viewer.ScrollableHeight))
                    {
                        // Scroll bar is in bottom Set auto-scroll mode
                        this._autoScroll = true;
                    }
                    else
                    {
                        // Scroll bar isn't in bottom Unset auto-scroll mode
                        this._autoScroll = false;
                    }
                }

                // Content scroll event : auto-scroll eventually
                if (this._autoScroll && !e.ExtentHeightChange.Equals(0))
                {
                    // Content changed and auto-scroll mode set Autoscroll
                    viewer.ScrollToVerticalOffset(viewer.ExtentHeight);
                }
            }
        }
Пример #3
0
        private void lstImageRecipe_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            var MyScroll = VisualTreeHelperEx.FindDescendantByType <ScrollViewer>(sender as ListView);

            if (e.Delta > 0)
            {
                MyScroll.LineLeft();
            }
            else
            {
                MyScroll.LineRight();
                e.Handled = true;
            }
        }