Files
ShrlAlgoToolkit/WPFluent.Gallery/ViewModels/Pages/CollectionsViewModel.cs
ShrlAlgo 4d35cadb56 更新
2025-07-11 09:20:23 +08:00

360 lines
9.6 KiB
C#

// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.
using System.Windows.Controls;
using WPFluent.Gallery.ControlsLookup;
using WPFluent.Gallery.Models;
using WPFluent.Gallery.Views.Pages.Collections;
namespace WPFluent.Gallery.ViewModels.Pages;
public partial class CollectionsViewModel : ViewModel
{
[ObservableProperty]
private TreeModelCollection<TreeTestModel> treeTestModel = CreateTestModel();
public static TreeModelCollection<TreeTestModel> CreateTestModel()
{
return new TreeModelCollection<TreeTestModel>()
{
Children = new(
[
new()
{
Column1 = "Test 1",
Column2 = "Test 1",
Column3 = "Test 1",
Children = new(
[
new()
{
Column1 = "Test 1.1",
Column2 = "Test 1.1",
Column3 = "Test 1.1",
Children = new(
[
new()
{
Column1 = "Test 1.2",
Column2 = "Test 1.2",
Column3 = "Test 1.2",
},
]),
},
]),
},
new()
{
Column1 = "Test 2",
Column2 = "Test 2",
Column3 = "Test 2",
}
]),
};
}
[ObservableProperty]
private ObservableCollection<Staff> staffList = [];
public CollectionsViewModel()
{
InitNode1Value();
}
private void InitNode1Value()
{
Staff staff = new Staff()
{
Name = "Alice",
Age = 30,
Sex = "Male",
Duty = "Manager",
IsExpanded = true
};
Staff staff2 = new Staff()
{
Name = "Alice1",
Age = 21,
Sex = "Male",
Duty = "Normal",
IsExpanded = true
};
Staff staff3 = new Staff()
{
Name = "Alice11",
Age = 21,
Sex = "Male",
Duty = "Normal"
};
staff2.StaffList.Add(staff3);
staff3 = new Staff()
{
Name = "Alice22",
Age = 21,
Sex = "Female",
Duty = "Normal"
};
staff2.StaffList.Add(staff3);
staff.StaffList.Add(staff2);
staff2 = new Staff()
{
Name = "Alice2",
Age = 22,
Sex = "Female",
Duty = "Normal"
};
staff.StaffList.Add(staff2);
staff2 = new Staff()
{
Name = "Alice3",
Age = 23,
Sex = "Female",
Duty = "Normal"
};
staff.StaffList.Add(staff2);
StaffList.Add(staff);
staff = new Staff()
{
Name = "Bob",
Age = 31,
Sex = "Male",
Duty = "CEO"
};
staff2 = new Staff()
{
Name = "Bob1",
Age = 24,
Sex = "Female",
Duty = "Normal"
};
staff.StaffList.Add(staff2);
staff2 = new Staff()
{
Name = "Bob2",
Age = 25,
Sex = "Female",
Duty = "Normal"
};
staff.StaffList.Add(staff2);
staff2 = new Staff()
{
Name = "Bob3",
Age = 26,
Sex = "Male",
Duty = "Normal"
};
staff.StaffList.Add(staff2);
StaffList.Add(staff);
staff = new Staff()
{
Name = "Cyber",
Age = 32,
Sex = "Female",
Duty = "Leader"
};
staff2 = new Staff()
{
Name = "Cyber1",
Age = 27,
Sex = "Female",
Duty = "Normal"
};
staff.StaffList.Add(staff2);
staff2 = new Staff()
{
Name = "Cyber2",
Age = 28,
Sex = "Female",
Duty = "Normal"
};
staff.StaffList.Add(staff2);
StaffList.Add(staff);
}
//[ObservableProperty]
//private ICollection<NavigationCard> _navigationCards = new ObservableCollection<NavigationCard>(
// ControlPages
// .FromNamespace(typeof(CollectionsPage).Namespace!)
// .Select(x => new NavigationCard()
// {
// Name = x.Name,
// Icon = x.Icon,
// Description = x.Description,
// PageType = x.PageType,
// })
//);
public static ObservableCollection<Grade> GenerateTreeViewItem()
{
ObservableCollection<Grade> grades = [];
Grade item = new() { GradeLevel = "一年级" };
item.Students.Add(new() { Name = "学生11" });
item.Students.Add(new() { Name = "学生12" });
item.Students.Add(new() { Name = "学生13" });
Grade item1 = new() { GradeLevel = "二年级" };
item1.Students.Add(new() { Name = "学生21" });
item1.Students.Add(new() { Name = "学生22" });
grades.Add(item);
grades.Add(item1);
return grades;
}
public ObservableCollection<Grade> SelectedItems { get; set; } = [];
public ObservableCollection<Grade> Grades { get; set; } = GenerateTreeViewItem();
[ObservableProperty]
private ObservableCollection<Product> productsCollection = GenerateProducts();
private static ObservableCollection<Product> GenerateProducts()
{
var random = new Random();
var products = new ObservableCollection<Product> { };
var adjectives = new[] { "Red", "Blueberry" };
var names = new[] { "Marmalade", "Dumplings", "Soup" };
Unit[] units = [Unit.Grams, Unit.Kilograms, Unit.Milliliters];
for (int i = 0; i < 50; i++)
{
products.Add(
new Product
{
ProductId = i,
ProductCode = i,
ProductName =
adjectives[random.Next(0, adjectives.Length)]
+ " "
+ names[random.Next(0, names.Length)],
Unit = units[random.Next(0, units.Length)],
UnitPrice = Math.Round(random.NextDouble() * 20.0, 3),
UnitsInStock = random.Next(0, 100),
IsVirtual = random.Next(0, 2) == 1,
}
);
}
return products;
}
[ObservableProperty]
private ObservableCollection<string> listBoxItems =
[
"Arial",
"Comic Sans MS",
"Courier New",
"Segoe UI",
"Times New Roman",
];
#region ListView
[ObservableProperty]
private ObservableCollection<Person> basicListViewItems = GeneratePersons();
private static ObservableCollection<Person> GeneratePersons()
{
var random = new Random();
var persons = new ObservableCollection<Person>();
var names = new[]
{
"John",
"Winston",
"Adrianna",
"Spencer",
"Phoebe",
"Lucas",
"Carl",
"Marissa",
"Brandon",
"Antoine",
"Arielle",
"Arielle",
"Jamie",
"Alexzander",
};
var surnames = new[]
{
"Doe",
"Tapia",
"Cisneros",
"Lynch",
"Munoz",
"Marsh",
"Hudson",
"Bartlett",
"Gregory",
"Banks",
"Hood",
"Fry",
"Carroll",
};
var companies = new[]
{
"Pineapple Inc.",
"Macrosoft Redmond",
"Amazing Basics Ltd",
"Megabyte Computers Inc",
"Roude Mics",
"XD Projekt Red S.A.",
"Lepo.co",
};
for (int i = 0; i < 50; i++)
{
persons.Add(
new Person(
names[random.Next(0, names.Length)],
surnames[random.Next(0, surnames.Length)],
companies[random.Next(0, companies.Length)]
)
);
}
return persons;
}
#endregion
}
[ObservableObject]
public partial class TreeTestModel : TreeModelObject<TreeTestModel>
{
[ObservableProperty]
private string? column1;
[ObservableProperty]
private string? column2;
[ObservableProperty]
private string? column3;
[ObservableProperty]
private bool isChecked = false;
}
public partial class Staff : ObservableObject
{
[ObservableProperty]
private string? name = null;
[ObservableProperty]
private int age;
[ObservableProperty]
private string? sex = null;
[ObservableProperty]
private string? duty = null;
[ObservableProperty]
private bool isChecked = true;
[ObservableProperty]
private bool isSelected = false;
[ObservableProperty]
private bool isExpanded = false;
[ObservableProperty]
private ObservableCollection<Staff> staffList = [];
}