NavigationPageMvvmPage.xaml.cs 926 B

1234567891011121314151617181920212223242526272829303132
  1. using Avalonia.Controls;
  2. using Avalonia.Interactivity;
  3. namespace ControlCatalog.Pages
  4. {
  5. public partial class NavigationPageMvvmPage : UserControl
  6. {
  7. private readonly NavigationPageMvvmShellViewModel _viewModel;
  8. private bool _initialized;
  9. public NavigationPageMvvmPage()
  10. {
  11. InitializeComponent();
  12. ISamplePageFactory pageFactory = new SamplePageFactory();
  13. ISampleNavigationService navigationService = new SampleNavigationService(DemoNav, pageFactory);
  14. _viewModel = new NavigationPageMvvmShellViewModel(navigationService);
  15. DataContext = _viewModel;
  16. Loaded += OnLoaded;
  17. }
  18. private async void OnLoaded(object? sender, RoutedEventArgs e)
  19. {
  20. if (_initialized)
  21. return;
  22. _initialized = true;
  23. await _viewModel.InitializeAsync();
  24. }
  25. }
  26. }