Created
June 6, 2019 10:24
-
-
Save mthalman/eebb465b90547dde788fb7d56175710f to your computer and use it in GitHub Desktop.
UWP TreeView Performance Issue
This file contains hidden or 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
<Page | |
x:Class="App.MainPage" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="using:App" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
mc:Ignorable="d" | |
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | |
<Grid> | |
<TreeView Name="KeywordTreeView" | |
ItemsSource="{x:Bind Nodes}"> | |
<TreeView.ItemTemplate> | |
<DataTemplate x:DataType="local:Node"> | |
<TreeViewItem ItemsSource="{x:Bind ChildNodes}" | |
IsExpanded="True" | |
Content="{x:Bind Name}"/> | |
</DataTemplate> | |
</TreeView.ItemTemplate> | |
</TreeView> | |
</Grid> | |
</Page> |
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.IO; | |
using System.Linq; | |
using System.Runtime.InteropServices.WindowsRuntime; | |
using Windows.Foundation; | |
using Windows.Foundation.Collections; | |
using Windows.UI.Xaml; | |
using Windows.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=402352&clcid=0x409 | |
namespace App2 | |
{ | |
/// <summary> | |
/// An empty page that can be used on its own or navigated to within a Frame. | |
/// </summary> | |
public sealed partial class MainPage : Page | |
{ | |
public MainPage() | |
{ | |
this.InitializeComponent(); | |
this.Nodes = new ObservableCollection<Node>(); | |
for (int i = 0; i < 100; i++) | |
{ | |
this.Nodes.Add(CreateNode(i.ToString(), 5)); | |
} | |
} | |
public ObservableCollection<Node> Nodes { get; } | |
private static Node CreateNode(string name, int depth) | |
{ | |
Node node = new Node(name); | |
if (depth > 0) | |
{ | |
depth--; | |
for (int i = 0; i < 10; i++) | |
{ | |
node.ChildNodes.Add(CreateNode(name + i, depth)); | |
} | |
} | |
return node; | |
} | |
} | |
public class Node | |
{ | |
public Node(string name) | |
{ | |
this.Name = name; | |
} | |
public string Name { get; } | |
public ObservableCollection<Node> ChildNodes { get; } = new ObservableCollection<Node>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment