New to Telerik UI for WPFStart a free 30-day trial

Bring RadTreeViewItem Into View With Offset When UI Virtualization is Enabled

Updated on Sep 15, 2025

Environment

ProductVersion
RadTreeView for WPF2023.3.1114

Description

How to bring an item into the viewport and apply an offset when using the BringPathIntoView method of RadTreeView and the UI virtualization is enabled.

The method will bring the item into the viewport, but because of the UI virtualization its position won't be top-left and therefore the applied offset won't work properly.

Solution

To make this work with a specific offset, you can manually scroll the ScrollViewer to the required position.

C#
	private void OnBringItemIntoView(MyTreeItem item, string path, double offsetY)
	{   
		this.radTreeView.BringPathIntoView(path);

		Dispatcher.BeginInvoke(new Action(() =>
		{
			RadTreeViewItem container = this.radTreeView.ContainerFromItemRecursive(item);
			Rect bounds = BoundsRelativeTo(container, this.radTreeView);

			var scrollViewer = this.radTreeView.FindChildByType<ScrollViewer>();
			double newOffset = scrollViewer.VerticalOffset + bounds.Y - offsetY;
			scrollViewer.ScrollToVerticalOffset(newOffset);

		}), (System.Windows.Threading.DispatcherPriority)4);
	}
	
	public static Rect BoundsRelativeTo(FrameworkElement child, Visual parent)
	{
		GeneralTransform gt = child.TransformToAncestor(parent);
		return gt.TransformBounds(new Rect(0, 0, child.ActualWidth, child.ActualHeight));
	}
In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support