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
- DelegatedStream.cs
- WebPartManager.cs
- FileNotFoundException.cs
- SectionInformation.cs
- ControlEvent.cs
- LiteralTextParser.cs
- PerformanceCounterLib.cs
- ComponentCache.cs
- TogglePattern.cs
- SafeNativeMethods.cs
- Overlapped.cs
- Size3DConverter.cs
- RuntimeConfigLKG.cs
- UnescapedXmlDiagnosticData.cs
- IDictionary.cs
- ToolStripManager.cs
- SubqueryTrackingVisitor.cs
- DbMetaDataCollectionNames.cs
- TextBounds.cs
- DefaultAssemblyResolver.cs
- CodeMemberEvent.cs
- OrderedHashRepartitionEnumerator.cs
- ListenerAdapterBase.cs
- UidManager.cs
- ControlPropertyNameConverter.cs
- SizeLimitedCache.cs
- WebPartZone.cs
- RectValueSerializer.cs
- PeerEndPoint.cs
- BamlStream.cs
- MultilineStringConverter.cs
- RegexRunner.cs
- PolicyStatement.cs
- FontStyles.cs
- Vector3DCollection.cs
- TreeNode.cs
- OdbcUtils.cs
- UrlAuthFailedErrorFormatter.cs
- PropertyGridView.cs
- Source.cs
- ResourceManager.cs
- EventProvider.cs
- KeyedHashAlgorithm.cs
- FreeFormDragDropManager.cs
- WebPartVerbCollection.cs
- TraceSource.cs
- KnownBoxes.cs
- PackageDigitalSignature.cs
- AggregateNode.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- FixedSOMGroup.cs
- PointLightBase.cs
- TdsParserHelperClasses.cs
- LinkDesigner.cs
- DataGridViewCellStyleConverter.cs
- ByteStreamBufferedMessageData.cs
- BaseCollection.cs
- UnsafeNativeMethods.cs
- AppDomainShutdownMonitor.cs
- _SslStream.cs
- HtmlInputRadioButton.cs
- TrustLevel.cs
- Int32Rect.cs
- SecurityElement.cs
- TargetConverter.cs
- StylusTip.cs
- CompModSwitches.cs
- Transactions.cs
- DataGridViewRowsRemovedEventArgs.cs
- WmlLabelAdapter.cs
- SecurityTokenAttachmentMode.cs
- PlainXmlSerializer.cs
- FilteredReadOnlyMetadataCollection.cs
- Type.cs
- SerializationInfoEnumerator.cs
- DrawingContextWalker.cs
- NamespaceEmitter.cs
- XPathAxisIterator.cs
- ContentFileHelper.cs
- DataGridLinkButton.cs
- LambdaCompiler.ControlFlow.cs
- DetailsViewDeletedEventArgs.cs
- __TransparentProxy.cs
- SelectionItemPattern.cs
- ConstantSlot.cs
- SQLDouble.cs
- MethodBody.cs
- SQLSingleStorage.cs
- ElementNotEnabledException.cs
- FontUnit.cs
- XmlStringTable.cs
- ResourceExpressionBuilder.cs
- ConvertBinder.cs
- SqlFormatter.cs
- Executor.cs
- x509utils.cs
- UnsafeNativeMethods.cs
- TreeViewItem.cs
- DataFormats.cs
- LogLogRecordHeader.cs