Using BringIntoView

3 posts, 0 answers
  1. Ed
    Ed avatar
    10 posts
    Member since:
    Jan 2012

    Posted 05 Jul 2012 Link to this post

    Hello,

    I am trying to bring the selected item into view programmatically. This is used during initial population of the tree. The item's ancestors are expanded, and then the item itself is selected by setting the property which is bound to SelectedItem in the RadTreeView. Finally, the RadTreeView's SelectionChanged event is handled as follows:

    private void RadTreeView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        RadTreeViewItem item = radTreeView.SelectedContainer;
     
        if (item != null)
        {
            item.BringIntoView();
        }
    }

    The expansion and selection works correctly, and the code above is fired after selection, and it identifies the correct item to bring into view - except that it does not bring it into view. The scroll bar remains at the top.

    In case of use, here is the XAML that we've used to define the RadTreeView:

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
            <telerik:RadTreeView Name="radTreeView" ItemTemplate="{StaticResource LocationTemplate}"
                                 ItemsSource="{Binding Path=LocationRoot}"
                                 SelectedItem="{Binding Path=SelectedLocation, Mode=TwoWay}"
                                 SelectionChanged="RadTreeView_SelectionChanged"
                                 />
        </ScrollViewer>
        <!-- etc. -->
    </Grid>

    I also notice that if I click on an item that is only partially in view, the code above does not bring it fully into view. This isn't a problem for us but maybe it indicates a problem with the code above.

    Your help is appreciated - thanks very much.

    Ed
  2. Ed
    Ed avatar
    10 posts
    Member since:
    Jan 2012

    Posted 05 Jul 2012 Link to this post

    Hi again,

    I solved the problem by removing the ScrollViewer from the XAML, which allows the RadTreeView to use its own scroll viewer. Oops!

    My only tiny complaint is that the Telerik scroll bars look different from the standard Silverlight scroll bars. Because we have another region on the same page that uses a standard scroll bar, it looks slightly odd. Is there any way to style the Telerik scroll bar to look like the standard?

    Thanks a lot

    Ed
  3. DevCraft banner
  4. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 10 Jul 2012 Link to this post

    Hello,

    I'm glad you have solved the issue.

    Regarding the scroll bars, you could set the appropriate style to the scroll viewer inside RadTreeView control template. The following link explains how to edit the TreeView style using expression blend: http://www.telerik.com/help/silverlight/common-styling-appearance-edit-control-templates-blend.html .
    This link provide a bit of information about the TreeView template structure: http://www.telerik.com/help/silverlight/radtreeview-styling-and-appearance-overview2.html .

    All the best,
    Hristo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top