-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
78 lines (69 loc) · 2 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
namespace TreeViewScrollingIssue;
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public TreeViewTestGroupItem[] GroupsItemSource { get; } =
[
new TreeViewTestGroupItem("Group I"),
new TreeViewTestGroupItem("Group II"),
new TreeViewTestGroupItem("Group III"),
new TreeViewTestGroupItem("Group IV"),
new TreeViewTestGroupItem("Group V"),
new TreeViewTestGroupItem("Group VI"),
new TreeViewTestGroupItem("Group VII")
];
public MainWindow()
{
InitializeComponent();
}
}
public sealed class TreeViewTestGroupItem(string title)
{
public string Title { get; } = title;
public TreeViewTestMemberItem[] MembersItemSource { get; } =
[
new("Member #01"),
new("Member #02"),
new("Member #03"),
new("Member #04"),
new("Member #05"),
new("Member #06"),
new("Member #07"),
new("Member #08"),
new("Member #09"),
new("Member #10"),
new("Member #11"),
new("Member #12"),
new("Member #13"),
new("Member #14"),
new("Member #15"),
new("Member #16"),
new("Member #17"),
new("Member #18"),
new("Member #19"),
new("Member #20")
];
}
public sealed class TreeViewTestMemberItem(string name)
{
public string Name { get; } = name;
}
public sealed class TreeViewTemplateSelector : DataTemplateSelector
{
public DataTemplate? GroupTemplate { get; set; }
public DataTemplate? MemberTemplate { get; set; }
protected override DataTemplate? SelectTemplateCore(object item)
{
return item switch
{
TreeViewTestGroupItem => GroupTemplate,
TreeViewTestMemberItem => MemberTemplate,
_ => throw new ArgumentOutOfRangeException(nameof(item))
};
}
}