Xcube-Studio / Natsurainko.FluentLauncher

Natsurainko.FluentLauncher A Minecraft launcher designed for Windows 11
https://fluentlauncher.natsurainko.work/
MIT License
282 stars 15 forks source link

[Bug] 设置 NavigationView.SelectedItem 属性导致触发 ItemInvoked 事件导致导航不正确 #267

Open vanja-san opened 3 weeks ago

vanja-san commented 3 weeks ago

Describe the bug

I went to the mods page, then clicked "back" and an error window popped up

Steps to reproduce the bug

-

Expected behavior

Nothing

Environment

Win - 23h2 FL - latest version

Attachment

System.InvalidCastException
System.InvalidCastException: Unable to cast object of type 'Natsurainko.FluentLauncher.ViewModels.Downloads.NavigationViewModel' to type 'Natsurainko.FluentLauncher.ViewModels.Settings.NavigationViewModel'.
   at Natsurainko.FluentLauncher.Views.Settings.NavigationPage.get_VM()
   at Natsurainko.FluentLauncher.Views.Settings.NavigationPage.ContentFrame_Navigated(Object sender, NavigationEventArgs e)
   at ABI.Microsoft.UI.Xaml.Navigation.NavigatedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)
--- End of stack trace from previous location ---
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.Controls.IFrameMethods.Navigate(IObjectReference _obj, Type sourcePageType, Object parameter)
   at FluentLauncher.Infra.WinUI.Navigation.WinUINavigationService.NavigateTo(String key, Object parameter)
   at Natsurainko.FluentLauncher.ViewModels.Downloads.NavigationViewModel.FluentLauncher.Infra.UI.Navigation.INavigationAware.OnNavigatedTo(Object parameter)
   at FluentLauncher.Infra.WinUI.Navigation.WinUINavigationService.ConfigureFrameContent(String key, Object parameter)
   at FluentLauncher.Infra.WinUI.Navigation.WinUINavigationService.GoBack()
   at Natsurainko.FluentLauncher.Views.ShellPage.BackButton_Click(Object sender, RoutedEventArgs e)
   at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)
natsurainko commented 3 weeks ago

I tested and found this bug before releasing it, and tried to fix it, but found that the problem was not fundamentally solved after the fix...

natsurainko commented 3 weeks ago

I just did some deep code tracing and found the root cause of the problem and fixed it. I will consider releasing a fix soon.