CatalogViewModel.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using MyMoviesWPF.MVVM.ViewModel.Core;
  6. using MyMoviesWPF.Models;
  7. using Microsoft.Toolkit.Mvvm.Input;
  8. using System.Windows;
  9. using MyMoviesWPF.MVVM.View;
  10. namespace MyMoviesWPF.MVVM.ViewModel
  11. {
  12. public class CatalogViewModel : BaseViewModel
  13. {
  14. public ObservableCollection<Movie> MoviesCollection { get; set; }
  15. private BaseViewModel _toolbar = new UserViewModel();
  16. private BaseViewModel _view = new UserViewModel();
  17. private Movie _movie;
  18. public CatalogViewModel()
  19. {
  20. MoviesCollection = new ObservableCollection<Movie>(Service.db.Movies.ToList());
  21. }
  22. public Movie OpenMovieWindow
  23. {
  24. get
  25. {
  26. return _movie;
  27. }
  28. set
  29. {
  30. _movie = value;
  31. Service.movie = _movie;
  32. _movie = null;
  33. foreach (Window item in Application.Current.Windows)
  34. {
  35. if (item.DataContext == this) item.Hide();
  36. }
  37. MovieView movieView = new MovieView();
  38. movieView.Show();
  39. }
  40. }
  41. public BaseViewModel CurrentToolbar
  42. {
  43. get { return _toolbar; }
  44. set
  45. {
  46. _toolbar = value;
  47. OnPropertyChanged();
  48. }
  49. }
  50. public BaseViewModel CurrentControlView
  51. {
  52. get { return _view; }
  53. set
  54. {
  55. _view = value;
  56. OnPropertyChanged();
  57. }
  58. }
  59. }
  60. }