From 7e891b0df8eb99d4b76b703f46853ee7250303be Mon Sep 17 00:00:00 2001 From: muqing <1966944300@qq.com> Date: Sun, 18 Aug 2024 07:27:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E7=9A=84?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RustTools/ViewModels/RankingViewModel.cs | 2 +- RustTools/ViewModels/ShellViewModel.cs | 2 + RustTools/Views/RankingPage.xaml | 2 + RustTools/Views/RankingPage.xaml.cs | 14 ++++++- RustTools/Views/ShellPage.xaml | 22 ++++++----- RustTools/Views/ShellPage.xaml.cs | 47 +++++++++++++++++++----- 6 files changed, 68 insertions(+), 21 deletions(-) diff --git a/RustTools/ViewModels/RankingViewModel.cs b/RustTools/ViewModels/RankingViewModel.cs index 9c80458..7607fe9 100644 --- a/RustTools/ViewModels/RankingViewModel.cs +++ b/RustTools/ViewModels/RankingViewModel.cs @@ -6,7 +6,7 @@ namespace RustTools.ViewModels; public partial class RankingViewModel : ObservableRecipient { - public ObservableCollection RankingList { get; set; } = new(); + public ObservableCollection? RankingList { get; set; } = new(); public RankingViewModel() { Init(); diff --git a/RustTools/ViewModels/ShellViewModel.cs b/RustTools/ViewModels/ShellViewModel.cs index c997d8c..19fa0d5 100644 --- a/RustTools/ViewModels/ShellViewModel.cs +++ b/RustTools/ViewModels/ShellViewModel.cs @@ -34,6 +34,8 @@ public partial class ShellViewModel : ObservableRecipient private void OnNavigated(object sender, NavigationEventArgs e) { + + System.GC.Collect(); IsBackEnabled = NavigationService.CanGoBack; if (e.SourcePageType == typeof(SettingsPage)) diff --git a/RustTools/Views/RankingPage.xaml b/RustTools/Views/RankingPage.xaml index 2e462c3..3694f72 100644 --- a/RustTools/Views/RankingPage.xaml +++ b/RustTools/Views/RankingPage.xaml @@ -6,6 +6,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:RustTools.Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:viewmodels="using:RustTools.ViewModels" + d:DataContext="{d:DesignInstance Type=viewmodels:RankingViewModel}" SizeChanged="Page_SizeChanged" mc:Ignorable="d"> diff --git a/RustTools/Views/RankingPage.xaml.cs b/RustTools/Views/RankingPage.xaml.cs index 3d48531..c1788c8 100644 --- a/RustTools/Views/RankingPage.xaml.cs +++ b/RustTools/Views/RankingPage.xaml.cs @@ -1,5 +1,8 @@ +using System.IO; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Navigation; +using RustTools.muqing; using RustTools.ViewModels; // To learn more about WinUI, the WinUI project structure, @@ -21,7 +24,6 @@ public sealed partial class RankingPage : Page ViewModel = App.GetService(); InitializeComponent(); list.ItemClick += HomePage.ListAClick; - } @@ -40,4 +42,14 @@ public sealed partial class RankingPage : Page ViewModel.ListTab(tag); } } + protected override void OnNavigatedFrom(NavigationEventArgs e) + { + // Release resources here + base.OnNavigatedFrom(e); + gj.sc(e); + ViewModel.RankingList = null; + Content = null; + DataContext = null; + } + } diff --git a/RustTools/Views/ShellPage.xaml b/RustTools/Views/ShellPage.xaml index 63b8b42..77fc499 100644 --- a/RustTools/Views/ShellPage.xaml +++ b/RustTools/Views/ShellPage.xaml @@ -39,29 +39,32 @@ IsSettingsVisible="True" SelectedItem="{x:Bind ViewModel.Selected, Mode=OneWay}"> - - + Icon="Home" + Tag="HomePage" /> + Icon="ContactInfo" + Tag="Concern" /> + Icon="List" + Tag="Ranking" /> - - + Icon="Contact2" + Tag="User" /> + - @@ -72,6 +75,7 @@ + diff --git a/RustTools/Views/ShellPage.xaml.cs b/RustTools/Views/ShellPage.xaml.cs index 03cdd76..1bc454e 100644 --- a/RustTools/Views/ShellPage.xaml.cs +++ b/RustTools/Views/ShellPage.xaml.cs @@ -1,9 +1,12 @@ -using Microsoft.UI.Xaml; +using System; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Input; using RustTools.Contracts.Services; using RustTools.Helpers; +using RustTools.muqing; using RustTools.ViewModels; using Windows.System; @@ -20,18 +23,11 @@ public sealed partial class ShellPage : Page public ShellPage(ShellViewModel viewModel) { - //< NavigationViewItem - // x: Uid = "Shell_Main" - // helpers: NavigationHelper.NavigateTo = "RustTools.ViewModels.MainViewModel"> - // < NavigationViewItem.Icon > - // < FontIcon FontFamily = "{StaticResource SymbolThemeFontFamily}" Glyph = "" /> - // - // - ViewModel = viewModel; InitializeComponent(); ViewModel.NavigationService.Frame = NavigationFrame; + //ViewModel.NavigationService.Frame.ElementSoundMode.isna = "False"; ViewModel.NavigationViewService.Initialize(NavigationViewControl); // TODO: Set the title bar icon by updating /Assets/WindowIcon.ico. @@ -42,9 +38,39 @@ public sealed partial class ShellPage : Page App.MainWindow.SetTitleBar(AppTitleBar); App.MainWindow.Activated += MainWindow_Activated; } - AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized(); + //AppTitleBarText.Text = "app_name".GetLocalized() + " " + "app_version".GetLocalized(); + //NavigationViewControl.SelectedItem = NavigationViewControl.MenuItems[0]; + //NavigationViewControl.SelectionChanged += NavigationViewControl_SelectionChanged; + //NavigateToPage("Home"); } + private void NavigationViewControl_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args) + { + System.GC.Collect(); + if (args.SelectedItem is NavigationViewItem selectedItem) + { + var tag = selectedItem.Tag.ToString(); + gj.sc(tag); + if (tag != null) + { + NavigateToPage(tag); + } + } + } + private void NavigateToPage(string pageTag) + { + var pageType = pageTag switch + { + "Home" => typeof(HomePage), + "Concern" => typeof(ConcernPage), + "Ranking" => typeof(RankingPage), + "User"=>typeof(UserPage), + "Module" => typeof(ModulePage), + "Settings" => typeof(SettingsPage), + _ => typeof(HomePage), + }; + NavigationFrame.Navigate(pageType); + } private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { //gj.sc(RequestedTheme); @@ -92,4 +118,5 @@ public sealed partial class ShellPage : Page args.Handled = result; } + }