// 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 = CreateTestModel(); public static TreeModelCollection CreateTestModel() { return new TreeModelCollection() { 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 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 _navigationCards = new ObservableCollection( // ControlPages // .FromNamespace(typeof(CollectionsPage).Namespace!) // .Select(x => new NavigationCard() // { // Name = x.Name, // Icon = x.Icon, // Description = x.Description, // PageType = x.PageType, // }) //); public static ObservableCollection GenerateTreeViewItem() { ObservableCollection 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 SelectedItems { get; set; } = []; public ObservableCollection Grades { get; set; } = GenerateTreeViewItem(); [ObservableProperty] private ObservableCollection productsCollection = GenerateProducts(); private static ObservableCollection GenerateProducts() { var random = new Random(); var products = new ObservableCollection { }; 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 listBoxItems = [ "Arial", "Comic Sans MS", "Courier New", "Segoe UI", "Times New Roman", ]; #region ListView [ObservableProperty] private ObservableCollection basicListViewItems = GeneratePersons(); private static ObservableCollection GeneratePersons() { var random = new Random(); var persons = new ObservableCollection(); 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 { [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 staffList = []; }