Files
ShrlAlgoToolkit/WPFluent.Gallery/ViewModels/Pages/CollectionsViewModel.cs
2025-04-24 20:56:44 +08:00

165 lines
4.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.Collections;
public partial class CollectionsViewModel : ViewModel
{
[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,
})
);
[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
private int _listViewSelectionModeComboBoxSelectedIndex = 0;
public int ListViewSelectionModeComboBoxSelectedIndex
{
get => _listViewSelectionModeComboBoxSelectedIndex;
set
{
_ = SetProperty(ref _listViewSelectionModeComboBoxSelectedIndex, value);
UpdateListViewSelectionMode(value);
}
}
[ObservableProperty]
private SelectionMode _listViewSelectionMode = SelectionMode.Single;
[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;
}
private void UpdateListViewSelectionMode(int selectionModeIndex)
{
ListViewSelectionMode = selectionModeIndex switch
{
1 => SelectionMode.Multiple,
2 => SelectionMode.Extended,
_ => SelectionMode.Single,
};
}
#endregion
}