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="20"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<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);
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:
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,
Thank you. This works
With the next SR we will provide a fix so that: you do not need to use ExpandParents() method and the Scrolling will work without it (note that using the ExpandParents() approach will prevent the ScrollIntoview to work correctly)
Note that in the following code:
=======void FindItem(CustomWebTreeItem item, string text) { ItemCollection items = item == null ? ComboTree.Items : item.Items;=======
you need to be using the XamWebTreeItems collection instead of the Items collection, like this:
XamWebTreeItemsCollection items = item == null ? TestTree.XamWebTreeItems : item.XamWebTreeItems;
Otherwise, there are sometimes problems because things are not done through XamWebTreeItems collection which was implemented to help with some of the limitations of the ItemsControl.
HTH,