MainWindowViewModel.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Avalonia.Controls;
  2. using help.Models;
  3. using help.Views;
  4. using ReactiveUI;
  5. namespace help.ViewModels
  6. {
  7. public class MainWindowViewModel : ViewModelBase
  8. {
  9. static SuharevaContext myConnection = new SuharevaContext();
  10. static SuharevaContext myConnection1 = new SuharevaContext();
  11. #pragma warning disable CA1822 // Mark members as static
  12. UserControl us = new Page1(); // по умолчанию в ContentControl загружается созданная Page1
  13. public UserControl US { get => us; set => this.RaiseAndSetIfChanged(ref us, value); }
  14. Page1ViewModel page1VM = new Page1ViewModel(myConnection); // объект для работы со свойствами из Page1, а ниже для свойство для привязки:
  15. public Page1ViewModel Page1VM { get => page1VM; set => page1VM = value; }
  16. Page2ViewModel page2VM = new Page2ViewModel(myConnection1);
  17. public Page2ViewModel Page2VM { get => page2VM; set => page2VM = value; }
  18. public void toPage2()
  19. {
  20. US = new Page2();
  21. }
  22. public void SaveNetwork()
  23. {
  24. myConnection.SaveChanges();
  25. US = new Page2();
  26. }
  27. public void SaveUser()
  28. {
  29. myConnection1.SaveChanges();
  30. US = new Page1();
  31. }
  32. #pragma warning restore CA1822 // Mark members as static
  33. }
  34. }