using MangaReader.WinUI.ViewModels; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media.Animation; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace MangaReader.WinUI.Views; public sealed partial class MainView : UserControl { private readonly MainViewModel viewModel; private readonly List<(string Tag, Type ViewType)> _tagViewMap = [ ("Search", typeof(SearchView)), ("Library", typeof(LibraryView)) ]; public MainView() { InitializeComponent(); viewModel = (MainViewModel)DataContext; } private void nvSample_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) { if (args.SelectedItem is not NavigationViewItem navigationViewItem) return; if (navigationViewItem.Tag is not string tagName) return; UpdateContent(tagName, null); } private void UpdateContent(string tag, NavigationTransitionInfo? transitionInfo) { Type? viewType = _tagViewMap.FirstOrDefault(x => x.Tag == tag).ViewType; if (viewType == null) return; ContentFrame.Navigate(viewType); } }