Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to prevent automatic horizontal scrolling on TreeView in base class when selecting an item in Silverlight
    text
    copied!<p>I'm trying to prevent the automatic horizontal scrolling on a tree view item when you select it in Silverlight. And I'm trying to do it in a base class.</p> <p>So far I haven't been able to manage it. I have tried the following code, but it executes and then the thing just scrolls anyway when I select it.</p> <pre><code>using System.Windows; using System.Windows.Controls; namespace MyControls { public class CustomTreeView : TreeView { private ScrollViewer _scrollViewer; protected override void OnSelectedItemChanged(RoutedPropertyChangedEventArgs&lt;object&gt; e) { base.OnSelectedItemChanged(e); _scrollViewer.ScrollToHorizontalOffset(0); } public override void OnApplyTemplate() { base.OnApplyTemplate(); _scrollViewer = GetTemplateChild("ScrollViewer") as ScrollViewer; } } } </code></pre> <p>I don't actually want to disable scrolling entirely -- if an item flies off the edge of the tree view I want the user to be able to scroll to it. What I am trying to do is to keep the tree where it is when I select a child node that may be longer than the width of the screen.</p> <p>I've tried RequestBringIntoView on a WrapPanel, but that's WPF-only, it seems. I've also tried doing this on UpdateLayout as well as SelectedItemChanged. All to no avail. I can't seem to find a general solution that I can have another class inherit from and use.</p> <p>Anyone have any ideas?</p> <p>Thanks!</p> <p>-Ari</p> <p>EDIT: The bounty states that I need to be able to do it in XAML. That was a typo on my part. I'll take code solutions as well. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload