Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TreeView missing children issue #2058

1 change: 1 addition & 0 deletions dev/TreeView/TestUI/TreeViewPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Button x:Name="ResetItemsSource" AutomationProperties.Name="ResetItemsSource" Content="ResetItemsSource" HorizontalAlignment="Stretch" Margin="1" Click="ResetItemsSource_Click"/>
<Button x:Name="ResetItemsSourceAsync" AutomationProperties.Name="ResetItemsSourceAsync" Content="ResetItemsSourceAsync" HorizontalAlignment="Stretch" Margin="1" Click="ResetItemsSourceAsync_Click"/>
<Button x:Name="ExpandRootNode" AutomationProperties.Name="ExpandRootNode" Content="ExpandRootNode" HorizontalAlignment="Stretch" Margin="1" Click="ExpandRootNode_Click"/>
<Button x:Name="SwapItemsSource" AutomationProperties.Name="SwapItemsSource" Content="SwapItemsSource" HorizontalAlignment="Stretch" Margin="1" Click="SwapItemsSource_Click"/>
Felix-Dev marked this conversation as resolved.
Show resolved Hide resolved
</StackPanel>
</ScrollViewer>
<ScrollViewer Grid.Column="1">
Expand Down
15 changes: 15 additions & 0 deletions dev/TreeView/TestUI/TreeViewPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -998,5 +998,20 @@ private void ExpandRootNode_Click(object sender, RoutedEventArgs e)
{
TestTreeViewItemsSource[0].IsExpanded = !TestTreeViewItemsSource[0].IsExpanded;
}

private bool isTreeView1SourceInUse = true;
private void SwapItemsSource_Click(object sender, RoutedEventArgs e)
{
if (!isTreeView1SourceInUse)
Felix-Dev marked this conversation as resolved.
Show resolved Hide resolved
{
this.ContentModeTestTreeView.ItemsSource = TestTreeViewItemsSource;
isTreeView1SourceInUse = true;
}
else
{
this.ContentModeTestTreeView.ItemsSource = TestTreeView2ItemsSource;
isTreeView1SourceInUse = false;
}
}
}
}
8 changes: 8 additions & 0 deletions dev/TreeView/TreeViewList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ void TreeViewList::OnContainerContentChanging(const winrt::IInspectable& /*sende
if (!args.InRecycleQueue())
{
auto targetItem = args.ItemContainer().as<winrt::TreeViewItem>();

// "Re-evaluate" the item source binding to trigger a TreeViewItem.OnPropertChanged(ItemsSourceProperty) changed call.
if (auto itemsSource = targetItem.ItemsSource())
Felix-Dev marked this conversation as resolved.
Show resolved Hide resolved
{
targetItem.ItemsSource(nullptr);
Felix-Dev marked this conversation as resolved.
Show resolved Hide resolved
targetItem.ItemsSource(itemsSource);
}

auto targetNode = NodeFromContainer(targetItem);
auto treeViewItem = winrt::get_self<TreeViewItem>(targetItem);
treeViewItem->UpdateIndentation(targetNode.Depth());
Expand Down