Beispiel #1
0
		/// <summary>
		/// Adds mouse wheel support to a <see cref="ScrollViewer"/>.
		/// As long as the <see cref="ScrollViewer"/> has focus, the mouse wheel can be used to scroll up and down.
		/// </summary>
		/// <param name="parentScrollViewer">The parent <see cref="ScrollViewer"/> which contains another <see cref="ScrollViewer" /> which should have mouse wheel scrolling support.</param>
		/// <param name="childScrollViewer">A child <see cref="ScrollViewer"/> to add mouse wheel scrolling support to.</param>
		/// <param name="scrollAmount">The amount to scroll by when the mouse wheel is moved.</param>
		/// <returns>The child <see cref="ScrollViewer"/>.</returns>
		public static ScrollViewer AddMouseWheelSupport(this ScrollViewer parentScrollViewer, ScrollViewer childScrollViewer, double scrollAmount)
		{
			MouseWheelSupport mouseWheelHelper = new MouseWheelSupport(childScrollViewer, parentScrollViewer);

			mouseWheelHelper.MouseWheelMoved += (source, eventArgs) =>
				{
					double delta = eventArgs.WheelDelta;

					delta *= scrollAmount;

					double newOffset = childScrollViewer.VerticalOffset - delta;
					if (newOffset > childScrollViewer.ScrollableHeight)
						newOffset = childScrollViewer.ScrollableHeight;
					else
					if (newOffset < 0)
						newOffset = 0;

					childScrollViewer.ScrollToVerticalOffset(newOffset);

					eventArgs.BrowserEventHandled = true;
				};

			return childScrollViewer;
		}
Beispiel #2
0
		/// <summary>
		/// Adds mouse wheel support to a <see cref="Slider"/>.
		/// As long as the <see cref="Slider"/> has focus, the mouse wheel can be used to scroll up and down.
		/// </summary>
		/// <param name="slider">The slider.</param>
		/// <param name="scrollAmount">The amount to scroll by when the mouse wheel is moved.</param>
		/// <returns>The <see cref="Slider"/>.</returns>
		public static Slider AddMouseWheelSupport(this Slider slider, double scrollAmount)
		{
			MouseWheelSupport mouseWheelHelper = new MouseWheelSupport(slider, null/*parentSlider*/);

			mouseWheelHelper.MouseWheelMoved += (source, eventArgs) =>
				{
					double delta = eventArgs.WheelDelta;

					delta *= scrollAmount;

					double newOffset = slider.Value - delta;
					if (newOffset < slider.Minimum)
						newOffset = slider.Minimum;
					else
					if (newOffset > slider.Maximum)
						newOffset = slider.Maximum;

					slider.Value = newOffset;

					eventArgs.BrowserEventHandled = true;
				};

			return slider;
		}