内存泄漏的临时解决方案
This commit is contained in:
parent
41d4624315
commit
7e891b0df8
|
@ -6,7 +6,7 @@ namespace RustTools.ViewModels;
|
||||||
|
|
||||||
public partial class RankingViewModel : ObservableRecipient
|
public partial class RankingViewModel : ObservableRecipient
|
||||||
{
|
{
|
||||||
public ObservableCollection<ModListResponse.ModData> RankingList { get; set; } = new();
|
public ObservableCollection<ModListResponse.ModData>? RankingList { get; set; } = new();
|
||||||
public RankingViewModel()
|
public RankingViewModel()
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
|
@ -34,6 +34,8 @@ public partial class ShellViewModel : ObservableRecipient
|
||||||
|
|
||||||
private void OnNavigated(object sender, NavigationEventArgs e)
|
private void OnNavigated(object sender, NavigationEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
System.GC.Collect();
|
||||||
IsBackEnabled = NavigationService.CanGoBack;
|
IsBackEnabled = NavigationService.CanGoBack;
|
||||||
|
|
||||||
if (e.SourcePageType == typeof(SettingsPage))
|
if (e.SourcePageType == typeof(SettingsPage))
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="using:RustTools.Views"
|
xmlns:local="using:RustTools.Views"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:viewmodels="using:RustTools.ViewModels"
|
||||||
|
d:DataContext="{d:DesignInstance Type=viewmodels:RankingViewModel}"
|
||||||
SizeChanged="Page_SizeChanged"
|
SizeChanged="Page_SizeChanged"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
using System.IO;
|
||||||
using Microsoft.UI.Xaml;
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
using Microsoft.UI.Xaml.Navigation;
|
||||||
|
using RustTools.muqing;
|
||||||
using RustTools.ViewModels;
|
using RustTools.ViewModels;
|
||||||
|
|
||||||
// To learn more about WinUI, the WinUI project structure,
|
// To learn more about WinUI, the WinUI project structure,
|
||||||
|
@ -21,7 +24,6 @@ public sealed partial class RankingPage : Page
|
||||||
ViewModel = App.GetService<RankingViewModel>();
|
ViewModel = App.GetService<RankingViewModel>();
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
list.ItemClick += HomePage.ListAClick;
|
list.ItemClick += HomePage.ListAClick;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,4 +42,14 @@ public sealed partial class RankingPage : Page
|
||||||
ViewModel.ListTab(tag);
|
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"
|
IsSettingsVisible="True"
|
||||||
SelectedItem="{x:Bind ViewModel.Selected, Mode=OneWay}">
|
SelectedItem="{x:Bind ViewModel.Selected, Mode=OneWay}">
|
||||||
<NavigationView.MenuItems>
|
<NavigationView.MenuItems>
|
||||||
|
|
||||||
|
|
||||||
<NavigationViewItem
|
<NavigationViewItem
|
||||||
x:Uid="HomePage"
|
x:Uid="HomePage"
|
||||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.HomePageViewModel"
|
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.HomePageViewModel"
|
||||||
Icon="Home" />
|
Icon="Home"
|
||||||
|
Tag="HomePage" />
|
||||||
<NavigationViewItem
|
<NavigationViewItem
|
||||||
x:Uid="Concern"
|
x:Uid="Concern"
|
||||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ConcernViewModel"
|
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ConcernViewModel"
|
||||||
Icon="ContactInfo" />
|
Icon="ContactInfo"
|
||||||
|
Tag="Concern" />
|
||||||
<NavigationViewItem
|
<NavigationViewItem
|
||||||
x:Uid="Ranking"
|
x:Uid="Ranking"
|
||||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.RankingViewModel"
|
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.RankingViewModel"
|
||||||
Icon="List" />
|
Icon="List"
|
||||||
|
Tag="Ranking" />
|
||||||
<NavigationViewItem
|
<NavigationViewItem
|
||||||
x:Uid="User"
|
x:Uid="User"
|
||||||
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.UserViewModel"
|
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.UserViewModel"
|
||||||
Icon="Contact2" />
|
Icon="Contact2"
|
||||||
<NavigationViewItem x:Uid="Module" helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ModuleViewModel">
|
Tag="User" />
|
||||||
|
<NavigationViewItem
|
||||||
|
x:Uid="Module"
|
||||||
|
helpers:NavigationHelper.NavigateTo="RustTools.ViewModels.ModuleViewModel"
|
||||||
|
Tag="Module">
|
||||||
<NavigationViewItem.Icon>
|
<NavigationViewItem.Icon>
|
||||||
<FontIcon Glyph="" />
|
<FontIcon Glyph="" />
|
||||||
<!-- 假设这是FolderOpen的Unicode码 -->
|
|
||||||
</NavigationViewItem.Icon>
|
</NavigationViewItem.Icon>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
</NavigationView.MenuItems>
|
</NavigationView.MenuItems>
|
||||||
|
@ -72,6 +75,7 @@
|
||||||
</Grid>
|
</Grid>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</NavigationView.HeaderTemplate>
|
</NavigationView.HeaderTemplate>
|
||||||
|
|
||||||
<i:Interaction.Behaviors>
|
<i:Interaction.Behaviors>
|
||||||
<behaviors:NavigationViewHeaderBehavior DefaultHeader="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}">
|
<behaviors:NavigationViewHeaderBehavior DefaultHeader="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}">
|
||||||
<behaviors:NavigationViewHeaderBehavior.DefaultHeaderTemplate>
|
<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;
|
||||||
|
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||||
using Microsoft.UI.Xaml.Input;
|
using Microsoft.UI.Xaml.Input;
|
||||||
|
|
||||||
using RustTools.Contracts.Services;
|
using RustTools.Contracts.Services;
|
||||||
using RustTools.Helpers;
|
using RustTools.Helpers;
|
||||||
|
using RustTools.muqing;
|
||||||
using RustTools.ViewModels;
|
using RustTools.ViewModels;
|
||||||
|
|
||||||
using Windows.System;
|
using Windows.System;
|
||||||
|
@ -20,18 +23,11 @@ public sealed partial class ShellPage : Page
|
||||||
|
|
||||||
public ShellPage(ShellViewModel viewModel)
|
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;
|
ViewModel = viewModel;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
ViewModel.NavigationService.Frame = NavigationFrame;
|
ViewModel.NavigationService.Frame = NavigationFrame;
|
||||||
|
//ViewModel.NavigationService.Frame.ElementSoundMode.isna = "False";
|
||||||
ViewModel.NavigationViewService.Initialize(NavigationViewControl);
|
ViewModel.NavigationViewService.Initialize(NavigationViewControl);
|
||||||
|
|
||||||
// TODO: Set the title bar icon by updating /Assets/WindowIcon.ico.
|
// 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.SetTitleBar(AppTitleBar);
|
||||||
App.MainWindow.Activated += MainWindow_Activated;
|
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)
|
private void OnLoaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
//gj.sc(RequestedTheme);
|
//gj.sc(RequestedTheme);
|
||||||
|
@ -92,4 +118,5 @@ public sealed partial class ShellPage : Page
|
||||||
|
|
||||||
args.Handled = result;
|
args.Handled = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user