private static void AutoScrollToBottom(this System.Windows.Controls.ScrollViewer scrollViewer) { if (Math.Abs(scrollViewer.VerticalOffset + scrollViewer.ActualHeight - scrollViewer.ExtentHeight) < 1) { scrollViewer.ScrollToBottom(); } }
private bool HandleScrollKeys(Key key) { ScrollViewer scroller = ScrollHost; if (scroller != null) { bool invert = (FlowDirection == FlowDirection.RightToLeft); switch (key) { case Key.Up: scroller.LineUp(); return(true); case Key.Down: scroller.LineDown(); return(true); case Key.Left: if (invert) { scroller.LineRight(); } else { scroller.LineLeft(); } return(true); case Key.Right: if (invert) { scroller.LineLeft(); } else { scroller.LineRight(); } return(true); case Key.Home: scroller.ScrollToTop(); return(true); case Key.End: scroller.ScrollToBottom(); return(true); case Key.PageUp: //if vertically scrollable - go vertical, otherwise horizontal if (DoubleUtil.GreaterThan(scroller.ExtentHeight, scroller.ViewportHeight)) { scroller.PageUp(); } else { scroller.PageLeft(); } return(true); case Key.PageDown: //if vertically scrollable - go vertical, otherwise horizontal if (DoubleUtil.GreaterThan(scroller.ExtentHeight, scroller.ViewportHeight)) { scroller.PageDown(); } else { scroller.PageRight(); } return(true); } } return(false); }
/// <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); } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); _scrollViewer = GetTemplateChild("scrollViewer") as ScrollViewer; if(_scrollViewer == null) return; _scrollViewer.ScrollToBottom(); _scrollViewer.ScrollChanged += OnScrollChanged; }
/// <summary> /// Update wallet log. /// </summary> /// <param name="text"></param> /// <param name="logLines"></param> /// <param name="textBox"></param> /// <param name="scrollViewer"></param> private void AddLogText(string text, IList<string> logLines, TextBox textBox, ScrollViewer scrollViewer) { while (logLines.Count >= 50) { logLines.RemoveAt(0); } logLines.Add(text); if (logLines.Count == 1) { textBox.Text = logLines.First(); } else { textBox.Text = logLines.Aggregate((l1, l2) => l1 + Environment.NewLine + l2); textBox.AppendText(Environment.NewLine); // Hack: make sure scroll to bottom works scrollViewer.ScrollToBottom(); } }
/// <summary> /// Handle keys related to scrolling. /// </summary> /// <param name="key">The key to handle.</param> /// <returns>A value indicating whether the key was handled.</returns> private bool HandleScrollKeys(Key key) { ScrollViewer scrollHost = ItemsControlHelper.ScrollHost; if (scrollHost != null) { // Some keys (e.g. Left/Right) need to be translated in RightToLeft mode Key invariantKey = InteractionHelper.GetLogicalKey(FlowDirection, key); switch (invariantKey) { case Key.PageUp: // Move horizontally if we've run out of room vertically if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight)) { scrollHost.PageLeft(); } else { scrollHost.PageUp(); } return(true); case Key.PageDown: // Move horizontally if we've run out of room vertically if (!NumericExtensions.IsGreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight)) { scrollHost.PageRight(); } else { scrollHost.PageDown(); } return(true); case Key.Home: scrollHost.ScrollToTop(); return(true); case Key.End: scrollHost.ScrollToBottom(); return(true); case Key.Left: scrollHost.LineLeft(); return(true); case Key.Right: scrollHost.LineRight(); return(true); case Key.Up: scrollHost.LineUp(); return(true); case Key.Down: scrollHost.LineDown(); return(true); } } return(false); }
// Token: 0x060058E9 RID: 22761 RVA: 0x00189730 File Offset: 0x00187930 private bool HandleScrollKeys(Key key) { ScrollViewer scrollHost = base.ScrollHost; if (scrollHost != null) { bool flag = base.FlowDirection == FlowDirection.RightToLeft; switch (key) { case Key.Prior: if (DoubleUtil.GreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight)) { scrollHost.PageUp(); } else { scrollHost.PageLeft(); } return(true); case Key.Next: if (DoubleUtil.GreaterThan(scrollHost.ExtentHeight, scrollHost.ViewportHeight)) { scrollHost.PageDown(); } else { scrollHost.PageRight(); } return(true); case Key.End: scrollHost.ScrollToBottom(); return(true); case Key.Home: scrollHost.ScrollToTop(); return(true); case Key.Left: if (flag) { scrollHost.LineRight(); } else { scrollHost.LineLeft(); } return(true); case Key.Up: scrollHost.LineUp(); return(true); case Key.Right: if (flag) { scrollHost.LineLeft(); } else { scrollHost.LineRight(); } return(true); case Key.Down: scrollHost.LineDown(); return(true); } } return(false); }