内存泄漏的临时解决方案
This commit is contained in:
parent
41d4624315
commit
7e891b0df8
|
@ -6,7 +6,7 @@ namespace RustTools.ViewModels;
|
|||
|
||||
public partial class RankingViewModel : ObservableRecipient
|
||||
{
|
||||
public ObservableCollection<ModListResponse.ModData> RankingList { get; set; } = new();
|
||||
public ObservableCollection<ModListResponse.ModData>? RankingList { get; set; } = new();
|
||||
public RankingViewModel()
|
||||
{
|
||||
Init();
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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">
|
||||
<Grid>
|
||||
|
|
|
@ -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<RankingViewModel>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,29 +39,32 @@
|
|||
IsSettingsVisible="True"
|
||||
SelectedItem="{x:Bind ViewModel.Selected, Mode=OneWay}">
|
||||
<NavigationView.MenuItems>
|
||||
|
||||
|
||||
<NavigationViewItem
|
||||
x:Uid="HomePage"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.HomePageViewModel"
|
||||
Icon="Home" />
|
||||
Icon="Home"
|
||||
Tag="HomePage" />
|
||||
<NavigationViewItem
|
||||
x:Uid="Concern"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ConcernViewModel"
|
||||
Icon="ContactInfo" />
|
||||
Icon="ContactInfo"
|
||||
Tag="Concern" />
|
||||
<NavigationViewItem
|
||||
x:Uid="Ranking"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.RankingViewModel"
|
||||
Icon="List" />
|
||||
Icon="List"
|
||||
Tag="Ranking" />
|
||||
<NavigationViewItem
|
||||
x:Uid="User"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.UserViewModel"
|
||||
Icon="Contact2" />
|
||||
<NavigationViewItem x:Uid="Module" helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ModuleViewModel">
|
||||
|
||||
Icon="Contact2"
|
||||
Tag="User" />
|
||||
<NavigationViewItem
|
||||
x:Uid="Module"
|
||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ModuleViewModel"
|
||||
Tag="Module">
|
||||
<NavigationViewItem.Icon>
|
||||
<FontIcon Glyph="" />
|
||||
<!-- 假设这是FolderOpen的Unicode码 -->
|
||||
</NavigationViewItem.Icon>
|
||||
</NavigationViewItem>
|
||||
</NavigationView.MenuItems>
|
||||
|
@ -72,6 +75,7 @@
|
|||
</Grid>
|
||||
</DataTemplate>
|
||||
</NavigationView.HeaderTemplate>
|
||||
|
||||
<i:Interaction.Behaviors>
|
||||
<behaviors:NavigationViewHeaderBehavior DefaultHeader="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}">
|
||||
<behaviors:NavigationViewHeaderBehavior.DefaultHeaderTemplate>
|
||||
|
|
|
@ -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 = "" />
|
||||
// </ NavigationViewItem.Icon >
|
||||
//</ NavigationViewItem >
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user