Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / AutoScrollHelper.cs / 1305376 / AutoScrollHelper.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System; using System.Windows; using System.Windows.Media; using System.Windows.Controls; using System.Windows.Input; internal static class AutoScrollHelper { const int scrollBuffer = 30; public static void AutoScroll(MouseEventArgs e, DependencyObject element) { FrameworkElement logicalView = element as FrameworkElement; while (element != null) { element = VisualTreeHelper.GetParent(element); if (element != null && element is ScrollViewer) { break; } } ScrollViewer scrollViewer = element as ScrollViewer; if (scrollViewer != null) { AutoScroll(e.GetPosition(scrollViewer), scrollViewer, logicalView != null ? e.GetPosition(logicalView) : (Point?)null, logicalView, 25, 25, 1); } } public static void AutoScroll(DragEventArgs e, ScrollViewer scrollViewer) { AutoScroll(e.GetPosition (scrollViewer), scrollViewer, null, null, 50, 50, 10); } static void AutoScroll(Point positionInScrollViewer, ScrollViewer scrollViewer, Point? positionInLogicalView, FrameworkElement logicalView, double scrollOnDragThresholdX, double scrollOnDragThresholdY, int scrollOnDragOffset) { double scrollViewerWidth = scrollViewer.ActualWidth; double scrollViewerHeight = scrollViewer.ActualHeight; double logicalViewWidth = 0; double logicalViewHeight = 0; if (logicalView != null) { logicalViewWidth = logicalView.ActualWidth; logicalViewHeight = logicalView.ActualHeight; } int heightToScroll = 0; int widthToScroll = 0; if (positionInScrollViewer.X > (scrollViewerWidth - scrollOnDragThresholdX) && (positionInLogicalView == null || positionInLogicalView.Value.X < (logicalViewWidth - scrollBuffer))) { widthToScroll = scrollOnDragOffset; } else if (positionInScrollViewer.X < scrollOnDragThresholdX && (positionInLogicalView == null || positionInLogicalView.Value.X > scrollBuffer)) { widthToScroll = -scrollOnDragOffset; } if (positionInScrollViewer.Y > (scrollViewerHeight - scrollOnDragThresholdY) && (positionInLogicalView == null || positionInLogicalView.Value.Y < logicalViewHeight - scrollBuffer)) { heightToScroll = scrollOnDragOffset; } else if (positionInScrollViewer.Y < scrollOnDragThresholdY && (positionInLogicalView == null || positionInLogicalView.Value.Y > scrollBuffer)) { heightToScroll = -scrollOnDragOffset; } if (widthToScroll != 0 || heightToScroll != 0) { scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + heightToScroll); scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + widthToScroll); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.View { using System; using System.Windows; using System.Windows.Media; using System.Windows.Controls; using System.Windows.Input; internal static class AutoScrollHelper { const int scrollBuffer = 30; public static void AutoScroll(MouseEventArgs e, DependencyObject element) { FrameworkElement logicalView = element as FrameworkElement; while (element != null) { element = VisualTreeHelper.GetParent(element); if (element != null && element is ScrollViewer) { break; } } ScrollViewer scrollViewer = element as ScrollViewer; if (scrollViewer != null) { AutoScroll(e.GetPosition(scrollViewer), scrollViewer, logicalView != null ? e.GetPosition(logicalView) : (Point?)null, logicalView, 25, 25, 1); } } public static void AutoScroll(DragEventArgs e, ScrollViewer scrollViewer) { AutoScroll(e.GetPosition (scrollViewer), scrollViewer, null, null, 50, 50, 10); } static void AutoScroll(Point positionInScrollViewer, ScrollViewer scrollViewer, Point? positionInLogicalView, FrameworkElement logicalView, double scrollOnDragThresholdX, double scrollOnDragThresholdY, int scrollOnDragOffset) { double scrollViewerWidth = scrollViewer.ActualWidth; double scrollViewerHeight = scrollViewer.ActualHeight; double logicalViewWidth = 0; double logicalViewHeight = 0; if (logicalView != null) { logicalViewWidth = logicalView.ActualWidth; logicalViewHeight = logicalView.ActualHeight; } int heightToScroll = 0; int widthToScroll = 0; if (positionInScrollViewer.X > (scrollViewerWidth - scrollOnDragThresholdX) && (positionInLogicalView == null || positionInLogicalView.Value.X < (logicalViewWidth - scrollBuffer))) { widthToScroll = scrollOnDragOffset; } else if (positionInScrollViewer.X < scrollOnDragThresholdX && (positionInLogicalView == null || positionInLogicalView.Value.X > scrollBuffer)) { widthToScroll = -scrollOnDragOffset; } if (positionInScrollViewer.Y > (scrollViewerHeight - scrollOnDragThresholdY) && (positionInLogicalView == null || positionInLogicalView.Value.Y < logicalViewHeight - scrollBuffer)) { heightToScroll = scrollOnDragOffset; } else if (positionInScrollViewer.Y < scrollOnDragThresholdY && (positionInLogicalView == null || positionInLogicalView.Value.Y > scrollBuffer)) { heightToScroll = -scrollOnDragOffset; } if (widthToScroll != 0 || heightToScroll != 0) { scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + heightToScroll); scrollViewer.ScrollToHorizontalOffset(scrollViewer.HorizontalOffset + widthToScroll); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ClientType.cs
- SecurityRuntime.cs
- GlobalizationAssembly.cs
- Propagator.JoinPropagator.cs
- SchemaHelper.cs
- FixedMaxHeap.cs
- PackUriHelper.cs
- Application.cs
- SymLanguageVendor.cs
- DataKey.cs
- Size3DConverter.cs
- Barrier.cs
- AmbientLight.cs
- HttpListenerRequest.cs
- ExceptionUtil.cs
- RuntimeEnvironment.cs
- Material.cs
- XPathDocumentBuilder.cs
- Deflater.cs
- SchemaTypeEmitter.cs
- AliasGenerator.cs
- ILGenerator.cs
- MemberInfoSerializationHolder.cs
- HotCommands.cs
- IISMapPath.cs
- RowTypePropertyElement.cs
- Compress.cs
- SubpageParaClient.cs
- InvalidComObjectException.cs
- AspCompat.cs
- IApplicationTrustManager.cs
- EnumerableRowCollectionExtensions.cs
- PrivilegedConfigurationManager.cs
- TabRenderer.cs
- AdRotator.cs
- TabletDeviceInfo.cs
- SolidBrush.cs
- StateBag.cs
- QuaternionAnimationBase.cs
- Geometry.cs
- Vector3DAnimation.cs
- ComponentChangingEvent.cs
- ApplicationContext.cs
- ApplicationTrust.cs
- WorkflowWebHostingModule.cs
- _SSPIWrapper.cs
- EntityWithKeyStrategy.cs
- XmlQueryTypeFactory.cs
- DataGridViewCheckBoxColumn.cs
- HashHelpers.cs
- SerializationException.cs
- AnimationClock.cs
- MemberRelationshipService.cs
- GradientStop.cs
- QuaternionAnimationUsingKeyFrames.cs
- TTSEvent.cs
- SymbolPair.cs
- HttpCacheVaryByContentEncodings.cs
- Floater.cs
- SafeHandles.cs
- ColumnMapCopier.cs
- SurrogateEncoder.cs
- MyContact.cs
- NameScopePropertyAttribute.cs
- TrackingAnnotationCollection.cs
- RegexWriter.cs
- Color.cs
- InputReportEventArgs.cs
- PropertyCollection.cs
- TextTreeNode.cs
- WebPartsSection.cs
- BaseTreeIterator.cs
- HtmlInputImage.cs
- PageSettings.cs
- PartialList.cs
- NamedPipeProcessProtocolHandler.cs
- WebPartAuthorizationEventArgs.cs
- HotSpotCollection.cs
- Slider.cs
- NumberAction.cs
- TagPrefixCollection.cs
- WinEventQueueItem.cs
- ContextMenu.cs
- SafeUserTokenHandle.cs
- MetadataItemCollectionFactory.cs
- MailWriter.cs
- recordstatefactory.cs
- wgx_exports.cs
- SQLDoubleStorage.cs
- VBCodeProvider.cs
- ObfuscationAttribute.cs
- StaticFileHandler.cs
- KeyGestureConverter.cs
- BamlTreeMap.cs
- CustomAttributeFormatException.cs
- SpeechSynthesizer.cs
- AttributeEmitter.cs
- ExpressionNode.cs
- HostedNamedPipeTransportManager.cs
- Assert.cs