// 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 _navigationCards = new ObservableCollection( ControlPages .FromNamespace(typeof(CollectionsPage).Namespace!) .Select(x => new NavigationCard() { Name = x.Name, Icon = x.Icon, Description = x.Description, PageType = x.PageType, }) ); [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 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 _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; } private void UpdateListViewSelectionMode(int selectionModeIndex) { ListViewSelectionMode = selectionModeIndex switch { 1 => SelectionMode.Multiple, 2 => SelectionMode.Extended, _ => SelectionMode.Single, }; } #endregion }