void ThumbDragStarted(object sender, DragStartedEventArgs e) { Thumb thumb = (Thumb)sender; ScrollBar scrollBar = thumb.FindVisualParent <ScrollBar>(); bool isVertical = scrollBar.Orientation == Orientation.Vertical; // Update the content in the ToolTip ScrollingPreviewData data = new ScrollingPreviewData(); data.UpdateScrollingValues(scrollBar); data.UpdateItem(this.AssociatedObject as ItemsControl, isVertical); this._previewToolTip = new ToolTip { PlacementTarget = (UIElement)sender, Placement = isVertical ? PlacementMode.Left : PlacementMode.Top, VerticalOffset = 0.0, HorizontalOffset = 0.0, ContentTemplate = (isVertical) ? this.VerticalScrollingPreviewTemplate : this.HorizontalScrollingPreviewTemplate, Content = data, IsOpen = true }; }
void ThumbDragDelta(object sender, DragDeltaEventArgs e) { Thumb thumb = (Thumb)sender; ScrollBar scrollBar = thumb.FindVisualParent <ScrollBar>(); // Check that we're within the range of the ScrollBar if ((this._previewToolTip != null) && (scrollBar.Value > scrollBar.Minimum) && (scrollBar.Value < scrollBar.Maximum)) { // This is a little trick to cause the ToolTip to update its position next to the Thumb if (scrollBar.Orientation == Orientation.Vertical) { this._previewToolTip.VerticalOffset = this._previewToolTip.VerticalOffset == 0.0 ? 0.001 : 0.0; } else { this._previewToolTip.HorizontalOffset = this._previewToolTip.HorizontalOffset == 0.0 ? 0.001 : 0.0; } } }