-
Notifications
You must be signed in to change notification settings - Fork 706
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 issue with single select and unrealized children on TreeView #2547
Merged
StephenLPeters
merged 6 commits into
microsoft:master
from
marcelwgn:treeview-expanding-changes-selection
Jun 3, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bd38a4d
Add test page
marcelwgn 6b768de
Add test
marcelwgn 5e63f0d
Fix the issue
marcelwgn d4df169
Clean up tests
marcelwgn 566b2d7
Remove empty line
marcelwgn afb8a92
Merge branch 'master' into treeview-expanding-changes-selection
marcelwgn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
dev/TreeView/TestUI/TreeViewUnrealizedChildrenTestPage.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<local:TestPage | ||
x:Class="MUXControlsTestApp.TreeViewUnrealizedChildrenTestPage" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:MUXControlsTestApp" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<StackPanel> | ||
<TextBlock Text="Unrealized children selection problem"/> | ||
<TextBlock x:Name="SelectedItemName" AutomationProperties.Name="SelectedItemName"/> | ||
<Button x:Name="GetSelectedItemName" AutomationProperties.Name="GetSelectedItemName" Content="Get selected item" Click="GetSelectedItemName_Click"/> | ||
<muxc:TreeView | ||
x:Name="UnrealizedTreeViewSelection" | ||
Expanding="UnrealizedTreeViewSelection_Expanding" | ||
Collapsed="UnrealizedTreeViewSelection_Collapsed"> | ||
|
||
</muxc:TreeView> | ||
</StackPanel> | ||
</local:TestPage> |
52 changes: 52 additions & 0 deletions
52
dev/TreeView/TestUI/TreeViewUnrealizedChildrenTestPage.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
|
||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace MUXControlsTestApp | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
public sealed partial class TreeViewUnrealizedChildrenTestPage : TestPage | ||
{ | ||
|
||
public TreeViewNode VirtualizingTestRootNode; | ||
public CustomContent CustomContentRootNode; | ||
|
||
public TreeViewUnrealizedChildrenTestPage() | ||
{ | ||
|
||
this.InitializeComponent(); | ||
CustomContentRootNode = new CustomContent(3); | ||
VirtualizingTestRootNode = CustomContentRootNode.GetTreeViewNode(); | ||
UnrealizedTreeViewSelection.RootNodes.Add(VirtualizingTestRootNode); | ||
} | ||
|
||
private void GetSelectedItemName_Click(object sender, RoutedEventArgs e) | ||
{ | ||
SelectedItemName.Text = ((UnrealizedTreeViewSelection.SelectedItem as TreeViewNode).Content as CustomContent).ToString(); | ||
} | ||
|
||
private void UnrealizedTreeViewSelection_Expanding(Microsoft.UI.Xaml.Controls.TreeView sender, Microsoft.UI.Xaml.Controls.TreeViewExpandingEventArgs args) | ||
{ | ||
VirtualizingDataSource.FillTreeNode(args.Node); | ||
} | ||
private void UnrealizedTreeViewSelection_Collapsed(Microsoft.UI.Xaml.Controls.TreeView sender, Microsoft.UI.Xaml.Controls.TreeViewCollapsedEventArgs args) | ||
{ | ||
VirtualizingDataSource.EmptyTreeNode(args.Node); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Microsoft.UI.Xaml.Controls; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Windows.ApplicationModel.Chat; | ||
|
||
namespace MUXControlsTestApp | ||
{ | ||
public class CustomContent | ||
{ | ||
public List<CustomContent> Children = new List<CustomContent>(); | ||
|
||
private int nestingLevel; | ||
private int index; | ||
|
||
public CustomContent(int nestingLevel = 3,int index=0) | ||
{ | ||
this.nestingLevel = nestingLevel; | ||
this.index = index; | ||
if(nestingLevel <= 0) | ||
{ | ||
return; | ||
} | ||
for (int i = 0; i < 4; i++) | ||
{ | ||
Children.Add(new CustomContent(nestingLevel - 1,i)); | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"Item: {this.index}; layer: {this.nestingLevel}"; | ||
} | ||
|
||
public TreeViewNode GetTreeViewNode() | ||
{ | ||
var node = new TreeViewNode(); | ||
node.Content = this; | ||
node.HasUnrealizedChildren = this.Children.Count != 0; | ||
return node; | ||
} | ||
} | ||
|
||
public class VirtualizingDataSource | ||
{ | ||
public static void FillTreeNode(TreeViewNode node) | ||
{ | ||
var customContent = (CustomContent)node.Content; | ||
if(customContent != null) | ||
{ | ||
if(node.HasUnrealizedChildren) | ||
{ | ||
foreach(var child in customContent.Children) | ||
{ | ||
node.Children.Add(child.GetTreeViewNode()); | ||
} | ||
} | ||
node.HasUnrealizedChildren = false; | ||
} | ||
} | ||
|
||
public static void EmptyTreeNode(TreeViewNode node) | ||
{ | ||
node.Children.Clear(); | ||
node.HasUnrealizedChildren = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that the desired behavior is not dependent on the 'HasUnrealizedChildren' flag. That is, when all the children are realized and we expand a node we would behave the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chingucoding do you know if this is the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know this method would handle both cases regardless of the HasUnrealizedChildren flag. This listener just acts when the children of the selected node have changed. However in the case of HasUnrealizedChildren, those children got added to the selected item, raising this listener. Since in SingleSelect, selecting an item unselects the previous item, this resulted in the faulty behavior.