当前位置: 首页>>代码示例>>C#>>正文


C# ScrollViewer.ScrollToVerticalOffset方法代码示例

本文整理汇总了C#中System.Windows.Controls.ScrollViewer.ScrollToVerticalOffset方法的典型用法代码示例。如果您正苦于以下问题:C# ScrollViewer.ScrollToVerticalOffset方法的具体用法?C# ScrollViewer.ScrollToVerticalOffset怎么用?C# ScrollViewer.ScrollToVerticalOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.ScrollViewer的用法示例。


在下文中一共展示了ScrollViewer.ScrollToVerticalOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ScrollByVerticalOffset

        /// <summary>
        /// Scroll a ScrollViewer vertically by a given offset.
        /// </summary>
        /// <param name="viewer">The ScrollViewer.</param>
        /// <param name="offset">The vertical offset to scroll.</param>
        private static void ScrollByVerticalOffset(ScrollViewer viewer, double offset)
        {
            Debug.Assert(viewer != null, "viewer should not be null!");

            offset += viewer.VerticalOffset;
            offset = Math.Max(Math.Min(offset, viewer.ExtentHeight), 0);
            viewer.ScrollToVerticalOffset(offset);
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:13,代码来源:ScrollExtensions.cs

示例2: AutoScroll

        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);
            }
        }
开发者ID:blacklensama,项目名称:1709,代码行数:48,代码来源:AutoScrollHelper.cs

示例3: set

        private void set(ScrollChangedEventArgs e, ScrollViewer sv, Canvas canvas)
        {
            if (e.ExtentHeightChange != 0 || e.ExtentWidthChange != 0)
            {
                Point? targetBefore = null;
                Point? targetNow = null;

                if (!lastMousePositionOnTarget.HasValue)
                {
                    if (lastCenterPositionOnTarget.HasValue)
                    {
                        var centerOfViewport = new Point(sv.ViewportWidth / 2, sv.ViewportHeight / 2);
                        Point centerOfTargetNow = sv.TranslatePoint(centerOfViewport, canvas);

                        targetBefore = lastCenterPositionOnTarget;
                        targetNow = centerOfTargetNow;
                    }
                }
                else
                {
                    targetBefore = lastMousePositionOnTarget;
                    targetNow = Mouse.GetPosition(canvas);

                    lastMousePositionOnTarget = null;
                }

                if (targetBefore.HasValue)
                {
                    double dXInTargetPixels = targetNow.Value.X - targetBefore.Value.X;
                    double dYInTargetPixels = targetNow.Value.Y - targetBefore.Value.Y;

                    double multiplicatorX = e.ExtentWidth / canvas.Width;
                    double multiplicatorY = e.ExtentHeight / canvas.Height;

                    double newOffsetX = sv.HorizontalOffset - dXInTargetPixels * multiplicatorX;
                    double newOffsetY = sv.VerticalOffset - dYInTargetPixels * multiplicatorY;

                    if (double.IsNaN(newOffsetX) || double.IsNaN(newOffsetY))
                    {
                        return;
                    }

                    sv.ScrollToHorizontalOffset(newOffsetX);
                    sv.ScrollToVerticalOffset(newOffsetY);
                }
            }
        }
开发者ID:koty,项目名称:ImageComparer,代码行数:47,代码来源:MainWindow.xaml.cs

示例4: ShowLog

        /// <summary>
        /// Shows log file in a separate child window on top
        /// </summary>
        public static void ShowLog()
        {
            var popup = new Popup();

            var text = new TextBlock();

            text.Width = 800;
            text.TextWrapping = TextWrapping.Wrap;

            try
            {
                text.Text = GetLogContents();
            }
            catch (Exception exception)
            {
                text.Text = string.Format("Cannot open log file, exception is\n {0}", exception.ToString());
            }
            

            var closeButton = new Button();
            closeButton.Content = "Close";
            closeButton.Click += (s, e) => popup.IsOpen = false;

            var scroll = new ScrollViewer();
            scroll.Background = new SolidColorBrush(Colors.White);
            scroll.Content = text;
            scroll.Height = 400;

            var content = new StackPanel();
            content.Children.Add(scroll);
            content.Children.Add(closeButton);

            popup.Child = content;
            popup.IsOpen = true;

            // scroll to the bottom
            scroll.UpdateLayout();
            scroll.ScrollToVerticalOffset(double.MaxValue);            
        }
开发者ID:ogvolkov,项目名称:Silverlight.SimpleLogger,代码行数:42,代码来源:SilverlightLogger.cs

示例5: HandleDragScrolling

        /// <summary>
        /// Handles scrolling the specified scroll viewer if the drag event indicates the drag
        /// operation is nearing the scroll viewers top or bottom boundaries.
        /// </summary>
        /// <param name="scrollViewer">The scroll viewer.</param>
        /// <param name="e">
        /// The <see cref="System.Windows.DragEventArgs" /> instance containing the event data.
        /// </param>
        private static void HandleDragScrolling(ScrollViewer scrollViewer, DragEventArgs e)
        {
            const int threshold = 20;
            const int offset = 10;

            var mousePoint = e.GetPosition(scrollViewer);

            if (mousePoint.Y < threshold)
            {
                scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - offset);
            }
            else if (mousePoint.Y > (scrollViewer.ActualHeight - threshold))
            {
                scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + offset);
            }
        }
开发者ID:reima,项目名称:codemaid,代码行数:24,代码来源:SpadeView.xaml.cs

示例6: AddScrollViewerMouseWheelSupport

        static ScrollViewer AddScrollViewerMouseWheelSupport(ScrollViewer scrollViewer, double scrollAmount)
        {
            if(mouseWheelHelper != null)
            {
                mouseWheelHelper.MouseWheelMoved += (source, eventArgs) =>
                {
                    var delta = eventArgs.WheelDelta;

                    delta *= scrollAmount;

                    if (eventArgs.IsHorizontal)
                    {
                        var newOffset = scrollViewer.HorizontalOffset - delta;

                        if (newOffset > scrollViewer.ScrollableWidth)
                            newOffset = scrollViewer.ScrollableWidth;
                        else if (newOffset < 0)
                            newOffset = 0;

                        scrollViewer.ScrollToHorizontalOffset(newOffset);
                    }
                    else
                    {
                        var newOffset = scrollViewer.VerticalOffset - delta;

                        if (newOffset > scrollViewer.ScrollableHeight)
                            newOffset = scrollViewer.ScrollableHeight;
                        else if (newOffset < 0)
                            newOffset = 0;

                        scrollViewer.ScrollToVerticalOffset(newOffset);
                    }
                    eventArgs.BrowserEventHandled = true;
                };
            }
            return scrollViewer;
        }
开发者ID:SmallMobile,项目名称:ranet-uilibrary-olap.latest-unstabilized,代码行数:37,代码来源:ScrollViewerMouseWheelSupport.cs

示例7: AppendToActivityLog

        public static void AppendToActivityLog(ScrollViewer scrollViewer, TextBlock textBlock, MessageLevelsEnum level, string text)
        {
            if (scrollViewer.Dispatcher.CheckAccess())
            {
                Run activityRun = new Run();
                activityRun.Text = text;
                activityRun.Foreground = GetBrushForMessageLevel(level);
                textBlock.Inlines.Add(activityRun);
                textBlock.Inlines.Add(new LineBreak());

                //scrollViewer.ScrollToVerticalOffset(scrollViewer.ScrollableHeight + 20);
                scrollViewer.UpdateLayout();
                scrollViewer.ScrollToVerticalOffset(Double.MaxValue);
            }
            else
            {
                scrollViewer.Dispatcher.BeginInvoke(new AppendToActivityLogDelegate(AppendToActivityLog), scrollViewer, textBlock, level, text);
            }
        }
开发者ID:sipsorcery,项目名称:sipsorcery,代码行数:19,代码来源:UIHelper.cs

示例8: AdjustScrollPosition

 /// <summary>
 /// This is the command scroll adjustment code which synchronizes two ScrollViewer instances.
 /// </summary>
 /// <param name="sv">ScrollViewer to adjust</param>
 /// <param name="e">Change in the source</param>
 /// <param name="hadjust">Horizontal adjustment</param>
 /// <param name="vadjust">Vertical adjustment</param>
 private static void AdjustScrollPosition(ScrollViewer sv, ScrollChangedEventArgs e, double hadjust, double vadjust)
 {
     if (e.HorizontalChange != 0 || e.ExtentWidthChange != 0)
     {
         if (e.HorizontalOffset == 0)
             sv.ScrollToLeftEnd();
         else if (e.HorizontalOffset >= e.ExtentWidth-5)
             sv.ScrollToRightEnd();
         else if (e.ExtentWidth + hadjust == sv.ExtentWidth)
             sv.ScrollToHorizontalOffset(e.HorizontalOffset + hadjust);
         else
             sv.ScrollToHorizontalOffset((sv.ExtentWidth * (e.HorizontalOffset / e.ExtentWidth)) + hadjust);
     }
     if (e.VerticalChange != 0 || e.ExtentHeightChange != 0)
     {
         if (e.VerticalOffset == 0)
             sv.ScrollToTop();
         else if (e.VerticalOffset >= e.ExtentHeight-5)
             sv.ScrollToBottom();
         else if (e.ExtentHeight + vadjust == sv.ExtentHeight)
             sv.ScrollToVerticalOffset(e.VerticalOffset + vadjust);
         else
             sv.ScrollToVerticalOffset((sv.ExtentHeight * (e.VerticalOffset / e.ExtentHeight)) + vadjust);
     }
 }
开发者ID:ssickles,项目名称:archive,代码行数:32,代码来源:SynchronizeScrollingBehavior.cs

示例9: PreScrollByPage

        /// <summary>
        /// Used when virtualization is on.  Moves the viewport so that HandleScrollByPage will work. 
        /// </summary> 
        private void PreScrollByPage(ScrollViewer scroller, bool up)
        { 
            double startTop, startBottom;   // offset of the top and bottom of the selected element from the top of the viewport
            double adjustmentOffset = 0d;   // offset we'll have to move the viewport in order to do the 'classic' page up / down algorithm
            double distance = 0d;           // distance from the furthest edge of either the selected item or the item we're about to select to the nearest edge of the viewport;
            double viewportHeight = scroller.ViewportHeight; 
            _selectedContainer.GetTopAndBottom(scroller, out startTop, out startBottom);
 
            // 
            // What we're doing here:
            // The TreeView page down algorithm walks the tree looking for the item a page up / down from the currently selected item. 
            // When virtualized that algorithm breaks down since some items aren't generated.
            //
            // VSP maintains one page of containers above and below the viewport.
            // Here we move the viewport so that the selected item or newly selected item, whichever is further, 
            // is only 1 page away from the top or bottom of the viewport.  That allows us to use the existing
            // non-virtualization algorithm. 
            // 

            if (startBottom < 0) 
            {
                // The selected item is above the viewport; if we page up the furthest distance will be the soon-to-be selected item
                distance = startBottom;
 
                if (up)
                { 
                    distance -= viewportHeight; 
                }
            } 
            else if (startTop > 0)
            {
                // The selected item is below the viewport; if we page down the furthest distance will be the soon-to-be selected item
                distance = startTop - viewportHeight; 

                if (!up) 
                { 
                    distance += viewportHeight;
                } 
            }

            if (Math.Abs(distance) > viewportHeight)
            { 
                // The selected or soon-to-be selected item is more than one page away from the nearest edge of the viewport.
                // Create the adjustment offset. Distance is delta between the viewport edge and the furthest item; 
                // we have to adjust by the viewport height to have the furthest item 1 page from the viewport 
                adjustmentOffset = distance < 0 ? distance + viewportHeight : distance - viewportHeight;
 
                //
                // Set the offset and update layout to ensure that all containers on the path from the selected item to the
                // item we want to select are generated.
                // 
                scroller.ScrollToVerticalOffset(scroller.VerticalOffset + adjustmentOffset);
                ContextLayoutManager layoutManager = ContextLayoutManager.From(Dispatcher); 
                layoutManager.UpdateLayout(); 
            }
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:59,代码来源:TreeView.cs

示例10: _DoAutoScroll

        /// <summary>
        /// Scrolls grid content if necessary.
        /// </summary>
        /// <param name="yPos">Dragged object position.</param>
        /// <param name="scrollViewer">Scroll viewer.</param>
        private void _DoAutoScroll(double yPos, ScrollViewer scrollViewer)
        {
            double bottomTolerance = BOTTOM_TOLERANCE;
            double topTolerance = _rowHeight * 2;

            Debug.Assert(_rowHeight != 0); // Must be initialized.

            if (scrollViewer == null)
                return;

            if (yPos < topTolerance) // Top of visible list?
            {
                // Scroll up.
                scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset - _rowHeight);
            }
            else if (yPos > this.ActualHeight - bottomTolerance) //Bottom of visible list?
            {
                //Scroll down.
                scrollViewer.ScrollToVerticalOffset(scrollViewer.VerticalOffset + _rowHeight);
            }
        }
开发者ID:erindm,项目名称:route-planner-csharp,代码行数:26,代码来源:DataGridControlEx.cs

示例11: GetScrollBarsForScrollViewer

    /// <summary>
    /// Attempts to extract the scrollbars that are within the scrollviewers
    /// visual tree. When extracted, event handlers are added to their ValueChanged events.
    /// </summary>
    private static void GetScrollBarsForScrollViewer(ScrollViewer scrollViewer)
    {
      ScrollBar scroll = GetScrollBar(scrollViewer, Orientation.Vertical);
      if (scroll != null)
      {
        // save a reference to this scrollbar on the attached property
        scrollViewer.SetValue(VerticalScrollBarProperty, scroll);

        // scroll the scrollviewer
        scrollViewer.ScrollToVerticalOffset(GetVerticalOffset(scrollViewer));

        // handle the changed event to update the exposed VerticalOffset
        scroll.ValueChanged += (s, e) => SetVerticalOffset(scrollViewer, e.NewValue);
      }

      scroll = GetScrollBar(scrollViewer, Orientation.Horizontal);
      if (scroll != null)
      {
        // save a reference to this scrollbar on the attached property
        scrollViewer.SetValue(HorizontalScrollBarProperty, scroll);

        // scroll the scrollviewer
        scrollViewer.ScrollToHorizontalOffset(GetHorizontalOffset(scrollViewer));

        // handle the changed event to update the exposed HorizontalOffset
        scroll.ValueChanged += (s, e) => scrollViewer.SetValue(HorizontalOffsetProperty, e.NewValue);
      }
    }
开发者ID:T1Easyware,项目名称:Soheil,代码行数:32,代码来源:ScrollOffsetBinding.cs

示例12: TranslationChanged

        /// <summary>
        /// 滑动改变
        /// </summary>
        /// <param name="isLeft">滑动方向 </param>
        /// <param name="scrollViewer">自动调整的控件</param>
        /// <param name="width">单个间隔的宽度</param>
        public int TranslationChanged(bool isLeft,ScrollViewer scrollViewer,double width)
        {
            int newSelected;
            if (!isLeft)
            {
                newSelected = _selecter + 1;
            }
            else
            {
                newSelected = _selecter - 1;
            }
            
            //循环切换
            if (newSelected < 0) newSelected = _effects.Count - 1;
            if (newSelected >= _effects.Count) newSelected = 0;
            
            //自动调整位置
            if (newSelected >= 3)
            {
                //判断方向
                if (scrollViewer.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled)
                {
                    scrollViewer.ScrollToHorizontalOffset(width * (newSelected - 2));
                }
                else
                {
                    scrollViewer.ScrollToVerticalOffset(width * (newSelected - 2));
                }
            }
            else
            {
                if (scrollViewer.HorizontalScrollBarVisibility != ScrollBarVisibility.Disabled)
                {
                    scrollViewer.ScrollToHorizontalOffset(0);
                }
                else
                {
                    scrollViewer.ScrollToVerticalOffset(0);
                }
            }

            //变化效果
            SelectedChanged(newSelected);
            
            return newSelected;
        }
开发者ID:saydax,项目名称:CameraDemo,代码行数:52,代码来源:CameraManager.cs

示例13: ScrollByVerticalOffset

 private static void ScrollByVerticalOffset(ScrollViewer viewer, double offset)
 {
     offset += viewer.VerticalOffset;
     offset = ScrollViewerExtensions.CoerceVerticalOffset(viewer, offset);
     viewer.ScrollToVerticalOffset(offset);
 }
开发者ID:sulerzh,项目名称:chart,代码行数:6,代码来源:ScrollViewerExtensions.cs

示例14: ScrollToCenter

 public static void ScrollToCenter(ScrollViewer scrollViewer)
 {
     scrollViewer.ScrollToHorizontalOffset(scrollViewer.ExtentWidth / 2 - scrollViewer.Width / 2);
     scrollViewer.ScrollToVerticalOffset(scrollViewer.ExtentHeight / 2 - scrollViewer.Height / 2);
 }
开发者ID:ignacy130,项目名称:FoursquareWP,代码行数:5,代码来源:Utilities.cs

示例15: ScrollByVerticalOffset

        /// <summary>
        /// Scroll a ScrollViewer vertically by a given offset.
        /// </summary>
        /// <param name="viewer">The ScrollViewer.</param>
        /// <param name="offset">The vertical offset to scroll.</param>
        private static void ScrollByVerticalOffset(ScrollViewer viewer, double offset)
        {
            Debug.Assert(viewer != null, "viewer should not be null!");

            offset += viewer.VerticalOffset;
            offset = CoerceVerticalOffset(viewer, offset);
            viewer.ScrollToVerticalOffset(offset);
        }
开发者ID:shijiaxing,项目名称:SilverlightToolkit,代码行数:13,代码来源:ScrollViewerExtensions.cs


注:本文中的System.Windows.Controls.ScrollViewer.ScrollToVerticalOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。