|
| 1 | +// This Source Code Form is subject to the terms of the MIT License. |
| 2 | +// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT. |
| 3 | +// Copyright (C) Leszek Pomianowski and WPF UI Contributors. |
| 4 | +// All Rights Reserved. |
| 5 | + |
| 6 | +using Wpf.Ui.Common.Interfaces; |
| 7 | +using Wpf.Ui.Demo.Services.Contracts; |
| 8 | +using Wpf.Ui.Mvvm.Contracts; |
| 9 | + |
| 10 | +namespace Wpf.Ui.Demo.ViewModels; |
| 11 | + |
| 12 | +public class DashboardViewModel : Wpf.Ui.Mvvm.ViewModelBase, INavigationAware |
| 13 | +{ |
| 14 | + private readonly INavigationService _navigationService; |
| 15 | + |
| 16 | + private readonly ITestWindowService _testWindowService; |
| 17 | + |
| 18 | + public DashboardViewModel(INavigationService navigationService, ITestWindowService testWindowService) |
| 19 | + { |
| 20 | + _navigationService = navigationService; |
| 21 | + _testWindowService = testWindowService; |
| 22 | + } |
| 23 | + |
| 24 | + protected override void OnViewCommand(object parameter = null) |
| 25 | + { |
| 26 | + if (parameter is not string parameterString) |
| 27 | + return; |
| 28 | + |
| 29 | + if (parameterString.StartsWith("navigate_to")) |
| 30 | + OnNavigateCommand(parameterString); |
| 31 | + |
| 32 | + if (parameterString.StartsWith("open_window")) |
| 33 | + OnOpenWindowCommand(parameterString); |
| 34 | + } |
| 35 | + |
| 36 | + public void OnNavigatedTo() |
| 37 | + { |
| 38 | + System.Diagnostics.Debug.WriteLine($"INFO | {typeof(DashboardViewModel)} navigated", "Wpf.Ui.Demo"); |
| 39 | + } |
| 40 | + |
| 41 | + public void OnNavigatedFrom() |
| 42 | + { |
| 43 | + System.Diagnostics.Debug.WriteLine($"INFO | {typeof(DashboardViewModel)} navigated", "Wpf.Ui.Demo"); |
| 44 | + } |
| 45 | + |
| 46 | + private void OnNavigateCommand(string parameter) |
| 47 | + { |
| 48 | + switch (parameter) |
| 49 | + { |
| 50 | + case "navigate_to_input": |
| 51 | + _navigationService.Navigate(typeof(Views.Pages.Input)); |
| 52 | + return; |
| 53 | + |
| 54 | + case "navigate_to_controls": |
| 55 | + _navigationService.Navigate(typeof(Views.Pages.Controls)); |
| 56 | + return; |
| 57 | + |
| 58 | + case "navigate_to_colors": |
| 59 | + _navigationService.Navigate(typeof(Views.Pages.Colors)); |
| 60 | + return; |
| 61 | + |
| 62 | + case "navigate_to_icons": |
| 63 | + _navigationService.Navigate(typeof(Views.Pages.Icons)); |
| 64 | + return; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private void OnOpenWindowCommand(string parameter) |
| 69 | + { |
| 70 | + switch (parameter) |
| 71 | + { |
| 72 | + case "open_window_store": |
| 73 | + _testWindowService.Show<Views.Windows.StoreWindow>(); |
| 74 | + return; |
| 75 | + |
| 76 | + case "open_window_manager": |
| 77 | + _testWindowService.Show<Views.Windows.TaskManagerWindow>(); |
| 78 | + return; |
| 79 | + |
| 80 | + case "open_window_editor": |
| 81 | + _testWindowService.Show<Views.Windows.EditorWindow>(); |
| 82 | + return; |
| 83 | + |
| 84 | + case "open_window_settings": |
| 85 | + _testWindowService.Show<Views.Windows.SettingsWindow>(); |
| 86 | + return; |
| 87 | + |
| 88 | + case "open_window_experimental": |
| 89 | + _testWindowService.Show<Views.Windows.ExperimentalWindow>(); |
| 90 | + return; |
| 91 | + } |
| 92 | + } |
| 93 | +} |
| 94 | + |
0 commit comments