-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
84 lines (68 loc) · 2.11 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
79
80
81
82
83
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Diagnostics;
using Windows.ApplicationModel.DataTransfer;
namespace TreeViewItemDropIssue;
/// <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 #1"),
new TreeViewTestGroupItem("Group #2")
];
public MainWindow()
{
InitializeComponent();
}
private void Grid_DragStarting(UIElement sender, DragStartingEventArgs args)
{
Debug.WriteLine("[-^-] Grid_DragStarting");
args.Data.RequestedOperation = DataPackageOperation.Copy;
args.Data.SetData("TestKey", "TestValue");
}
private void TreeViewItem_DragOver(object sender, DragEventArgs e)
{
Debug.WriteLine("[-->] TreeViewItem_DragOver");
e.AcceptedOperation = DataPackageOperation.Copy;
}
private void TreeViewItem_DragLeave(object sender, DragEventArgs e)
{
Debug.WriteLine("[<--] TreeViewItem_DragLeave");
}
private void TreeViewItem_Drop(object sender, DragEventArgs e)
{
Debug.WriteLine("[-v-] TreeViewItem_Drop <!>");
}
}
public sealed class TreeViewTestGroupItem(string title)
{
public string Title { get; } = title;
public TreeViewTestMemberItem[] MembersItemSource { get; } =
[
new("Member #1"),
new("Member #2"),
new("Member #3")
];
}
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))
};
}
}