Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2589
ScrollIntoView not working
posted

Hello,

I recursively fill the tree and after that I have to find some item by its header. I need to expand all item's parent nodes and scroll view to this item. I get item selected but tree won't scroll to that item. What am I doing wrong?

This tree opens in popup window, I don't know if this is important or not.

This is my code which searches for the item:

XAML

 

 

<Grid x:Name="ComboWndPopup"  Width="350" Height="400" >

        <Grid.RowDefinitions>

            <RowDefinition Height="*"></RowDefinition>

            <RowDefinition Height="30"></RowDefinition>

            <RowDefinition Height="30"></RowDefinition>

            <RowDefinition Height="20"></RowDefinition>

        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="*"></ColumnDefinition>

            <ColumnDefinition Width="*"></ColumnDefinition>

            <ColumnDefinition Width="*"></ColumnDefinition>

        </Grid.ColumnDefinitions>

 

 

        <Controls:XamWebTree x:Name="ComboTree" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3">

        </Controls:XamWebTree>

 

        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Grid.Column="0" Grid.Row="1"  Grid.ColumnSpan="3">

            <TextBlock Text="Search:" VerticalAlignment="Bottom"></TextBlock>

            <input:AutoCompleteBox Height="22" Width="200" VerticalAlignment="Bottom"  x:Name="tboxAutocomplete" SelectionChanged="tboxAutocomplete_SelectionChanged"></input:AutoCompleteBox>

        </StackPanel>

        <CheckBox x:Name="chBoxAlphabet" VerticalAlignment="Bottom" Grid.Column="0" Grid.Row="2" Content="Sort" IsChecked="False" Click="chBoxAlphabet_Click"></CheckBox>

 

        <Button Content="OK" Click="ComboPopupOk_Click" Grid.Row="3" Grid.Column="0"></Button>

        <Button Content="Send NULL" Click="ComboPopupEmpty_Click" Grid.Row="3" Grid.Column="1"></Button>

        <Button Content="Cancel" Click="ComboPopupCancel_Click" Grid.Row="3" Grid.Column="2"></Button>

    </Grid>

 

C#

//CustomWebTreeItem inherits XamWebTreeItem to disable double click behavior

 

void FindItem(CustomWebTreeItem item, string text)

        {

            ItemCollection items = item == null ? ComboTree.Items : item.Items;

 

            foreach (CustomWebTreeItem treeItem in items)

            {

                if (treeItem.Header.ToString() == text)

                {

                    treeItem.IsSelected = true;

                    ExpandParents(treeItem);

                    treeItem.ScrollItemIntoView();                    

                    return;

                }

                if (treeItem.HasChildren)

                    FindItem(treeItem, text);

            }            

        }

 

     // recursively expands all item's parents

        private void ExpandParents(CustomWebTreeItem item)

        {

            if (item.Parent == null || item.Parent is XamWebTree) return;

            ((CustomWebTreeItem) item.Parent).IsExpanded = true;

            ExpandParents((CustomWebTreeItem)item.Parent);

        }

 

 

Parents
No Data
Reply
  • 5595
    Verified Answer
    posted

    Hi,

    This seems like an issue in the control. I will submit a bug item for it in our bug tracking system to track it and post a message whenever there is an update on the matter.

    In the meantime, it seems something related to the timing and when the ScrollItemIntoView() is called. You could try replacing:

    treeItem.ScrollItemIntoView();

    with e.g.:

     

    DispatcherTimer timer = new DispatcherTimer();

    timer.Interval = new TimeSpan(0, 0, 1);
    timer.Tick += (s, e) =>
    {
     treeItem.ScrollItemIntoView();
     timer.Stop();
    };
    timer.Start();

     

    to see what will happen.

     

     

     

    Thanks for the feedback,

     

     

Children