This is a migrated thread and some comments may be shown as answers.

Using BringIntoView

2 Answers 94 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 05 Jul 2012, 10:06 AM
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 Answers, 1 is accepted

Sort by
0
Ed
Top achievements
Rank 1
answered on 05 Jul 2012, 10:17 AM
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
0
Hristo
Telerik team
answered on 10 Jul 2012, 06:59 AM
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 >>

Tags
TreeView
Asked by
Ed
Top achievements
Rank 1
Answers by
Ed
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or