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
- XmlSchemaCompilationSettings.cs
- TableCell.cs
- XAMLParseException.cs
- AvtEvent.cs
- DoubleAnimationClockResource.cs
- TreeWalkHelper.cs
- TransportSecurityProtocol.cs
- CommandConverter.cs
- EventLogPermissionEntry.cs
- TypeGeneratedEventArgs.cs
- PathSegment.cs
- WaveHeader.cs
- ParsedAttributeCollection.cs
- SpellerHighlightLayer.cs
- ExpressionEditorSheet.cs
- ObjectPropertyMapping.cs
- SHA1CryptoServiceProvider.cs
- ReverseInheritProperty.cs
- FixedHyperLink.cs
- PackWebRequest.cs
- MaterializeFromAtom.cs
- XmlDataSourceNodeDescriptor.cs
- TypeConverterHelper.cs
- EDesignUtil.cs
- HttpApplicationFactory.cs
- ProgramPublisher.cs
- XamlTreeBuilderBamlRecordWriter.cs
- PropertyEmitterBase.cs
- ImportOptions.cs
- EncoderParameter.cs
- VisualStyleElement.cs
- Hashtable.cs
- QfeChecker.cs
- CodePrimitiveExpression.cs
- Compilation.cs
- IUnknownConstantAttribute.cs
- PreservationFileWriter.cs
- TransformerConfigurationWizardBase.cs
- VerificationException.cs
- ObjectDataSource.cs
- OpCopier.cs
- Path.cs
- ErrorActivity.cs
- DataGridCell.cs
- StylusButton.cs
- MD5.cs
- WSFederationHttpSecurityElement.cs
- HybridDictionary.cs
- SamlAuthenticationClaimResource.cs
- SqlFacetAttribute.cs
- LocatorPartList.cs
- NativeWindow.cs
- X500Name.cs
- RelationshipEntry.cs
- XmlSchemaSimpleContent.cs
- ADMembershipUser.cs
- DPTypeDescriptorContext.cs
- XPathScanner.cs
- ModulesEntry.cs
- PerformanceCounterPermission.cs
- SyndicationCategory.cs
- SqlIdentifier.cs
- TraceLog.cs
- FileIOPermission.cs
- FixedHyperLink.cs
- BufferCache.cs
- SqlUDTStorage.cs
- ResourceDescriptionAttribute.cs
- BitmapImage.cs
- PngBitmapEncoder.cs
- GeometryDrawing.cs
- PeerDefaultCustomResolverClient.cs
- ServicePoint.cs
- BitStack.cs
- GroupBox.cs
- DataGridViewCell.cs
- SQLDecimalStorage.cs
- EllipseGeometry.cs
- ResourcePool.cs
- Path.cs
- UdpTransportSettingsElement.cs
- RawMouseInputReport.cs
- complextypematerializer.cs
- HttpAsyncResult.cs
- EndpointIdentityExtension.cs
- CannotUnloadAppDomainException.cs
- ComboBoxRenderer.cs
- CategoryNameCollection.cs
- RelationshipEndCollection.cs
- PointUtil.cs
- RequestQueue.cs
- TTSEngineTypes.cs
- MenuAdapter.cs
- BoolExpr.cs
- DetailsViewDeleteEventArgs.cs
- SignatureDescription.cs
- ChannelDispatcherCollection.cs
- DictionaryKeyPropertyAttribute.cs
- TextStore.cs
- XmlHierarchyData.cs