-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with single select and unrealized children on TreeView (#2547)
* Add test page * Add test * Fix the issue * Clean up tests * Remove empty line
- Loading branch information
Showing
8 changed files
with
193 additions
and
3 deletions.
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