├── .gitignore
├── AvaloniaHugeTree.sln
└── AvaloniaHugeTree
├── App.xaml
├── App.xaml.cs
├── AvaloniaHugeTree.csproj
├── LevelPaddingConverter.cs
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── MainWindowViewModel.cs
├── Program.cs
├── PropertyChangedBase.cs
├── TreeNodeModel.cs
└── nuget.config
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | ## Visual Studio Code specific files and folder
7 | .vscode/*
8 | !.vscode/settings.json
9 | !.vscode/tasks.json
10 | !.vscode/launch.json
11 | !.vscode/extensions.jsons
12 |
13 | # User-specific files
14 | *.suo
15 | *.user
16 | *.userosscache
17 | *.sln.docstates
18 |
19 | # User-specific files (MonoDevelop/Xamarin Studio)
20 | *.userprefs
21 |
22 | # Build results
23 | [Dd]ebug/
24 | [Dd]ebugPublic/
25 | [Rr]elease/
26 | [Rr]eleases/
27 | x64/
28 | x86/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Ll]og/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUNIT
47 | *.VisualState.xml
48 | TestResult.xml
49 |
50 | # Build Results of an ATL Project
51 | [Dd]ebugPS/
52 | [Rr]eleasePS/
53 | dlldata.c
54 |
55 | # Benchmark Results
56 | BenchmarkDotNet.Artifacts/
57 |
58 | # .NET Core
59 | project.lock.json
60 | project.fragment.lock.json
61 | artifacts/
62 | **/Properties/launchSettings.json
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_i.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *.log
88 | *.vspscc
89 | *.vssscc
90 | .builds
91 | *.pidb
92 | *.svclog
93 | *.scc
94 |
95 | # Chutzpah Test files
96 | _Chutzpah*
97 |
98 | # Visual C++ cache files
99 | ipch/
100 | *.aps
101 | *.ncb
102 | *.opendb
103 | *.opensdf
104 | *.sdf
105 | *.cachefile
106 | *.VC.db
107 | *.VC.VC.opendb
108 |
109 | # Visual Studio profiler
110 | *.psess
111 | *.vsp
112 | *.vspx
113 | *.sap
114 |
115 | # Visual Studio Trace Files
116 | *.e2e
117 |
118 | # TFS 2012 Local Workspace
119 | $tf/
120 |
121 | # Guidance Automation Toolkit
122 | *.gpState
123 |
124 | # ReSharper is a .NET coding add-in
125 | _ReSharper*/
126 | *.[Rr]e[Ss]harper
127 | *.DotSettings.user
128 |
129 | # JustCode is a .NET coding add-in
130 | .JustCode
131 |
132 | # TeamCity is a build add-in
133 | _TeamCity*
134 |
135 | # DotCover is a Code Coverage Tool
136 | *.dotCover
137 |
138 | # AxoCover is a Code Coverage Tool
139 | .axoCover/*
140 | !.axoCover/settings.json
141 |
142 | # Visual Studio code coverage results
143 | *.coverage
144 | *.coveragexml
145 |
146 | # NCrunch
147 | _NCrunch_*
148 | .*crunch*.local.xml
149 | nCrunchTemp_*
150 |
151 | # MightyMoose
152 | *.mm.*
153 | AutoTest.Net/
154 |
155 | # Web workbench (sass)
156 | .sass-cache/
157 |
158 | # Installshield output folder
159 | [Ee]xpress/
160 |
161 | # DocProject is a documentation generator add-in
162 | DocProject/buildhelp/
163 | DocProject/Help/*.HxT
164 | DocProject/Help/*.HxC
165 | DocProject/Help/*.hhc
166 | DocProject/Help/*.hhk
167 | DocProject/Help/*.hhp
168 | DocProject/Help/Html2
169 | DocProject/Help/html
170 |
171 | # Click-Once directory
172 | publish/
173 |
174 | # Publish Web Output
175 | *.[Pp]ublish.xml
176 | *.azurePubxml
177 | # Note: Comment the next line if you want to checkin your web deploy settings,
178 | # but database connection strings (with potential passwords) will be unencrypted
179 | *.pubxml
180 | *.publishproj
181 |
182 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
183 | # checkin your Azure Web App publish settings, but sensitive information contained
184 | # in these scripts will be unencrypted
185 | PublishScripts/
186 |
187 | # NuGet Packages
188 | *.nupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 |
214 | # Visual Studio cache files
215 | # files ending in .cache can be ignored
216 | *.[Cc]ache
217 | # but keep track of directories ending in .cache
218 | !*.[Cc]ache/
219 |
220 | # Others
221 | ClientBin/
222 | ~$*
223 | *~
224 | *.dbmdl
225 | *.dbproj.schemaview
226 | *.jfm
227 | *.pfx
228 | *.publishsettings
229 | orleans.codegen.cs
230 |
231 | # Including strong name files can present a security risk
232 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
233 | #*.snk
234 |
235 | # Since there are multiple workflows, uncomment next line to ignore bower_components
236 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
237 | #bower_components/
238 |
239 | # RIA/Silverlight projects
240 | Generated_Code/
241 |
242 | # Backup & report files from converting an old project file
243 | # to a newer Visual Studio version. Backup files are not needed,
244 | # because we have git ;-)
245 | _UpgradeReport_Files/
246 | Backup*/
247 | UpgradeLog*.XML
248 | UpgradeLog*.htm
249 | ServiceFabricBackup/
250 | *.rptproj.bak
251 |
252 | # SQL Server files
253 | *.mdf
254 | *.ldf
255 | *.ndf
256 |
257 | # Business Intelligence projects
258 | *.rdl.data
259 | *.bim.layout
260 | *.bim_*.settings
261 | *.rptproj.rsuser
262 |
263 | # Microsoft Fakes
264 | FakesAssemblies/
265 |
266 | # GhostDoc plugin setting file
267 | *.GhostDoc.xml
268 |
269 | # Node.js Tools for Visual Studio
270 | .ntvs_analysis.dat
271 | node_modules/
272 |
273 | # Visual Studio 6 build log
274 | *.plg
275 |
276 | # Visual Studio 6 workspace options file
277 | *.opt
278 |
279 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
280 | *.vbw
281 |
282 | # Visual Studio LightSwitch build output
283 | **/*.HTMLClient/GeneratedArtifacts
284 | **/*.DesktopClient/GeneratedArtifacts
285 | **/*.DesktopClient/ModelManifest.xml
286 | **/*.Server/GeneratedArtifacts
287 | **/*.Server/ModelManifest.xml
288 | _Pvt_Extensions
289 |
290 | # Paket dependency manager
291 | .paket/paket.exe
292 | paket-files/
293 |
294 | # FAKE - F# Make
295 | .fake/
296 |
297 | # JetBrains Rider
298 | .idea/
299 | *.sln.iml
300 |
301 | # CodeRush
302 | .cr/
303 |
304 | # Python Tools for Visual Studio (PTVS)
305 | __pycache__/
306 | *.pyc
307 |
308 | # Cake - Uncomment if you are using it
309 | # tools/**
310 | # !tools/packages.config
311 |
312 | # Tabs Studio
313 | *.tss
314 |
315 | # Telerik's JustMock configuration file
316 | *.jmconfig
317 |
318 | # BizTalk build output
319 | *.btp.cs
320 | *.btm.cs
321 | *.odx.cs
322 | *.xsd.cs
323 |
324 | # OpenCover UI analysis results
325 | OpenCover/
326 |
327 | # Azure Stream Analytics local run output
328 | ASALocalRun/
329 |
330 | # MSBuild Binary and Structured Log
331 | *.binlog
332 |
333 | # NVidia Nsight GPU debugger configuration file
334 | *.nvuser
335 |
336 | # MFractors (Xamarin productivity tool) working folder
337 | .mfractor/
338 |
--------------------------------------------------------------------------------
/AvaloniaHugeTree.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaHugeTree", "AvaloniaHugeTree\AvaloniaHugeTree.csproj", "{6C2D6F90-FFE1-4BD1-A112-930564E42855}"
4 | EndProject
5 | Global
6 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
7 | Debug|Any CPU = Debug|Any CPU
8 | Release|Any CPU = Release|Any CPU
9 | EndGlobalSection
10 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
11 | {6C2D6F90-FFE1-4BD1-A112-930564E42855}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12 | {6C2D6F90-FFE1-4BD1-A112-930564E42855}.Debug|Any CPU.Build.0 = Debug|Any CPU
13 | {6C2D6F90-FFE1-4BD1-A112-930564E42855}.Release|Any CPU.ActiveCfg = Release|Any CPU
14 | {6C2D6F90-FFE1-4BD1-A112-930564E42855}.Release|Any CPU.Build.0 = Release|Any CPU
15 | EndGlobalSection
16 | EndGlobal
17 |
--------------------------------------------------------------------------------
/AvaloniaHugeTree/App.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/AvaloniaHugeTree/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia;
2 | using Avalonia.Controls.ApplicationLifetimes;
3 | using Avalonia.Markup.Xaml;
4 |
5 | namespace AvaloniaHugeTree
6 | {
7 | public class App : Application
8 | {
9 | public override void Initialize()
10 | {
11 | AvaloniaXamlLoader.Load(this);
12 | }
13 |
14 | public override void OnFrameworkInitializationCompleted()
15 | {
16 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
17 | {
18 | desktop.MainWindow = new MainWindow()
19 | {
20 | DataContext = new MainWindowViewModel()
21 | };
22 | }
23 |
24 | base.OnFrameworkInitializationCompleted();
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/AvaloniaHugeTree/AvaloniaHugeTree.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | WinExe
4 | netcoreapp3.0
5 |
6 |
7 |
8 | %(Filename)
9 |
10 |
11 | Designer
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/AvaloniaHugeTree/LevelPaddingConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Avalonia;
4 | using Avalonia.Data.Converters;
5 |
6 | namespace AvaloniaHugeTree
7 | {
8 | public class LevelPaddingConverter : IValueConverter
9 | {
10 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11 | {
12 | if (value is int level)
13 | {
14 | return new Thickness(20 * level + 10, 5, 5, 5);
15 | }
16 | return new Thickness();
17 | }
18 |
19 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20 | {
21 | throw new NotImplementedException();
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/AvaloniaHugeTree/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 | Visible items:
15 |
16 | Total items:
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/AvaloniaHugeTree/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Avalonia;
2 | using Avalonia.Controls;
3 | using Avalonia.Markup.Xaml;
4 |
5 | namespace AvaloniaHugeTree
6 | {
7 | public class MainWindow : Window
8 | {
9 | public MainWindow()
10 | {
11 | InitializeComponent();
12 | this.AttachDevTools();
13 | }
14 |
15 | private void InitializeComponent()
16 | {
17 | AvaloniaXamlLoader.Load(this);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/AvaloniaHugeTree/MainWindowViewModel.cs:
--------------------------------------------------------------------------------
1 | namespace AvaloniaHugeTree
2 | {
3 | public class MainWindowViewModel : PropertyChangedBase
4 | {
5 | private bool _recountQueued = false;
6 | public RootTreeNodeModel TreeRoot { get; }
7 | public int TotalItems { get; set; }
8 |
9 | public MainWindowViewModel()
10 | {
11 | var root = new RootTreeNodeModel()
12 | {
13 | Name = "Root",
14 | IsExpanded = true
15 | };
16 | Populate(root, 5);
17 | root.ForceResync();
18 | TreeRoot = root;
19 | TotalItems = Count(root);
20 | }
21 |
22 | int Count(TreeNodeModel node)
23 | {
24 | int cnt = 1;
25 | foreach (var ch in node.Children)
26 | cnt += Count(ch);
27 | return cnt;
28 | }
29 |
30 | void Populate(TreeNodeModel node, int levels)
31 | {
32 | if (levels == 0)
33 | return;
34 | for (var c = 0; c < 10; c++)
35 | {
36 | var ch = new TreeNodeModel
37 | {
38 | Name = "Child " + c,
39 | IsExpanded = levels>1
40 | };
41 | if (levels == 1)
42 | SetupAutoAdd(ch);
43 | node.AddChild(ch);
44 | Populate(ch, levels - 1);
45 | }
46 | }
47 |
48 | private void SetupAutoAdd(TreeNodeModel node)
49 | {
50 | node.PropertyChanged += (s, e) =>
51 | {
52 | if (node.IsExpanded && node.Children.Count == 0)
53 | {
54 | for (var c = 0; c < 20; c++)
55 | {
56 | var ch = new TreeNodeModel
57 | {
58 | Name = "Auto-added child " + c
59 | };
60 | SetupAutoAdd(ch);
61 | node.AddChild(ch);
62 | }
63 |
64 | TotalItems += 20;
65 | RaisePropertyChanged(nameof(TotalItems));
66 | }
67 | };
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/AvaloniaHugeTree/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia;
3 | using Avalonia.Controls;
4 | using Avalonia.Controls.ApplicationLifetimes;
5 | using Avalonia.Logging.Serilog;
6 |
7 | namespace AvaloniaHugeTree
8 | {
9 | class Program
10 | {
11 | // Initialization code. Don't use any Avalonia, third-party APIs or any
12 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
13 | // yet and stuff might break.
14 | public static void Main(string[] args) => BuildAvaloniaApp()
15 | .StartWithClassicDesktopLifetime(args);
16 |
17 | // Avalonia configuration, don't remove; also used by visual designer.
18 | public static AppBuilder BuildAvaloniaApp()
19 | => AppBuilder.Configure()
20 | .UsePlatformDetect()
21 | .LogToDebug();
22 | }
23 | }
--------------------------------------------------------------------------------
/AvaloniaHugeTree/PropertyChangedBase.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel;
2 | using System.Runtime.CompilerServices;
3 |
4 | namespace AvaloniaHugeTree
5 | {
6 | public class PropertyChangedBase : INotifyPropertyChanged
7 | {
8 | public event PropertyChangedEventHandler PropertyChanged;
9 |
10 | public void SetAndRaise(ref T field, T newValue, [CallerMemberName]string name = null)
11 | {
12 | if (!Equals(field, newValue))
13 | {
14 | field = newValue;
15 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
16 | }
17 | }
18 |
19 | public void RaisePropertyChanged(string name) =>
20 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
21 | }
22 | }
--------------------------------------------------------------------------------
/AvaloniaHugeTree/TreeNodeModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Avalonia.Collections;
5 | using Avalonia.Threading;
6 | using JetBrains.Annotations;
7 |
8 | namespace AvaloniaHugeTree
9 | {
10 | public class RootTreeNodeModel : TreeNodeModel
11 | {
12 | public IAvaloniaReadOnlyList VisibleChildren => _visibleChildren;
13 | private AvaloniaList _visibleChildren = new AvaloniaList();
14 |
15 | public RootTreeNodeModel()
16 | {
17 | _root = new Root(this);
18 | }
19 |
20 | class Root : ITreeNodeRoot
21 | {
22 | private readonly RootTreeNodeModel _root;
23 | private bool _updateEnqueued;
24 |
25 | public Root(RootTreeNodeModel root)
26 | {
27 | _root = root;
28 | }
29 |
30 | public void EnqueueUpdate()
31 | {
32 | if (!_updateEnqueued)
33 | {
34 | _updateEnqueued = true;
35 | Dispatcher.UIThread.Post(Update, DispatcherPriority.Background);
36 | }
37 | }
38 |
39 | private static void AppendItems(AvaloniaList list, TreeNodeModel node)
40 | {
41 | list.Add(node);
42 | if(node.IsExpanded)
43 | foreach(var ch in node.Children)
44 | AppendItems(list, ch);
45 | }
46 |
47 | public void Update()
48 | {
49 | _updateEnqueued = false;
50 | var list = new AvaloniaList();
51 | AppendItems(list, _root);
52 |
53 | _root._visibleChildren = new AvaloniaList(list);
54 | _root.RaisePropertyChanged(nameof(_root.VisibleChildren));
55 | }
56 |
57 |
58 | }
59 |
60 | public void ForceResync() => ((Root) _root).Update();
61 | }
62 |
63 | public class TreeNodeModel : PropertyChangedBase
64 | {
65 | private bool _isExpanded;
66 | private string _name;
67 | private List _children = new List();
68 | protected ITreeNodeRoot _root;
69 | public int Level { get; private set; }
70 |
71 | protected interface ITreeNodeRoot
72 | {
73 | void EnqueueUpdate();
74 | }
75 |
76 | public bool IsExpanded
77 | {
78 | get => _isExpanded;
79 | set
80 | {
81 | SetAndRaise(ref _isExpanded, value);
82 | _root?.EnqueueUpdate();
83 | }
84 | }
85 |
86 | public string Name
87 | {
88 | get => _name;
89 | set => SetAndRaise(ref _name, value);
90 | }
91 |
92 | public IReadOnlyList Children => _children;
93 |
94 | public void InsertChild(int index, TreeNodeModel child)
95 | {
96 | if (child._root != null)
97 | throw new InvalidOperationException();
98 | _children.Insert(index, child);
99 | child.SetRoot(_root, Level + 1);
100 | _root?.EnqueueUpdate();
101 | }
102 |
103 | public void RemoveChildAt(int index)
104 | {
105 | var child = _children[index];
106 | _children.RemoveAt(index);
107 | child.SetRoot(null, 0);
108 | _root?.EnqueueUpdate();
109 | }
110 |
111 | protected void SetRoot(ITreeNodeRoot root, int level)
112 | {
113 | _root = root;
114 | Level = root == null ? -1 : level;
115 | foreach (var child in _children)
116 | child.SetRoot(root, level + 1);
117 | }
118 |
119 | public void RemoveChild(TreeNodeModel child)
120 | {
121 | var idx = _children.IndexOf(child);
122 | if (idx != -1)
123 | RemoveChildAt(idx);
124 | }
125 |
126 | public void AddChild(TreeNodeModel child) => InsertChild(_children.Count, child);
127 |
128 | }
129 | }
--------------------------------------------------------------------------------
/AvaloniaHugeTree/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------