38 lines
1.6 KiB
C#
38 lines
1.6 KiB
C#
using Avalonia.Controls;
|
|
|
|
internal sealed record DeviceCategory(string Label, string Value, params DeviceCategory[] Children);
|
|
|
|
internal static class DeviceCatalog
|
|
{
|
|
internal static readonly DeviceCategory[] Categories =
|
|
[
|
|
new DeviceCategory("全部", ""),
|
|
new DeviceCategory("手机", "",
|
|
new DeviceCategory("手机", "phone"), new DeviceCategory("折叠屏", "foldable"),
|
|
new DeviceCategory("阔折叠", "widefold"), new DeviceCategory("三折叠", "triplefold")),
|
|
new DeviceCategory("平板", "", new DeviceCategory("平板", "tablet")),
|
|
new DeviceCategory("2in1", "", new DeviceCategory("2in1", "2in1"), new DeviceCategory("折叠2in1", "2in1 Foldable")),
|
|
new DeviceCategory("电视", "", new DeviceCategory("电视", "tv")),
|
|
new DeviceCategory("穿戴设备", "", new DeviceCategory("智能表", "wearable"), new DeviceCategory("儿童表", "wearablekid")),
|
|
new DeviceCategory("车机", "", new DeviceCategory("车机", "car"))
|
|
];
|
|
|
|
internal static readonly Dictionary<string, string> TypeNames = Categories
|
|
.SelectMany(group => new[] { group }.Concat(group.Children))
|
|
.Where(node => node.Value.Length > 0)
|
|
.ToDictionary(node => node.Value, node => node.Label);
|
|
|
|
internal static TreeViewItem CreateItem(DeviceCategory node)
|
|
{
|
|
var item = new TreeViewItem
|
|
{
|
|
Header = node.Label,
|
|
Tag = node,
|
|
IsExpanded = node.Children.Length > 0
|
|
};
|
|
foreach (var child in node.Children)
|
|
item.Items.Add(CreateItem(child));
|
|
return item;
|
|
}
|
|
}
|