ComboBoxPageViewModel.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Linq;
  4. using Avalonia.Controls;
  5. using Avalonia.Controls.Selection;
  6. using MiniMvvm;
  7. namespace ControlCatalog.ViewModels
  8. {
  9. public class ComboBoxPageViewModel : ViewModelBase
  10. {
  11. private bool _wrapSelection;
  12. private string _textValue = string.Empty;
  13. private IdAndName? _selectedItem = null;
  14. public bool WrapSelection
  15. {
  16. get => _wrapSelection;
  17. set => this.RaiseAndSetIfChanged(ref _wrapSelection, value);
  18. }
  19. public string TextValue
  20. {
  21. get => _textValue;
  22. set => this.RaiseAndSetIfChanged(ref _textValue, value);
  23. }
  24. public IdAndName? SelectedItem
  25. {
  26. get => _selectedItem;
  27. set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
  28. }
  29. public ObservableCollection<IdAndName> Values { get; set; } = new ObservableCollection<IdAndName>
  30. {
  31. new IdAndName(){ Id = "Id 1", Name = "Name 1", SearchText = "A" },
  32. new IdAndName(){ Id = "Id 2", Name = "Name 2", SearchText = "B" },
  33. new IdAndName(){ Id = "Id 3", Name = "Name 3", SearchText = "C" },
  34. new IdAndName(){ Id = "Id 4", Name = "Name 4", SearchText = "D" },
  35. new IdAndName(){ Id = "Id 5", Name = "Name 5", SearchText = "E" },
  36. };
  37. }
  38. public class IdAndName
  39. {
  40. public string? Id { get; set; }
  41. public string? Name { get; set; }
  42. public string? SearchText { get; set; }
  43. }
  44. }