Compare commits

..

1 Commits

Author SHA1 Message Date
Muyuan Li (from Dev Box)
12e9ee42ca fix(Settings): handle null Exception in Frame_NavigationFailed to prevent NullReferenceException
When NavigationFailedEventArgs.Exception is null, the original code threw a
NullReferenceException instead of a meaningful error. Use null-coalescing to
throw an InvalidOperationException with context about the failed page.
2026-04-29 17:56:18 +08:00
5 changed files with 6 additions and 5 deletions

View File

@@ -129,8 +129,8 @@ public partial class ContentPageViewModel : PageViewModel, ICommandBarContext
UpdateDetails();
model.ItemsChanged += Model_ItemsChanged;
FetchContent();
model.ItemsChanged += Model_ItemsChanged;
DoOnUiThread(
() =>

View File

@@ -44,9 +44,9 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference<IPag
UpdateProperty(nameof(Root));
}
FetchContent();
model.PropChanged += Model_PropChanged;
model.ItemsChanged += Model_ItemsChanged;
FetchContent();
}
// Theoretically, we should unify this with the one in CommandPalettePageViewModelFactory

View File

@@ -209,8 +209,8 @@ public sealed partial class DockBandViewModel : ExtensionObjectViewModel
var list = command.Model.Unsafe as IListPage;
if (list is not null)
{
list.ItemsChanged += HandleItemsChanged;
InitializeFromList(list);
list.ItemsChanged += HandleItemsChanged;
}
else
{

View File

@@ -957,8 +957,8 @@ public partial class ListViewModel : PageViewModel, IDisposable
Filters?.InitializeProperties();
UpdateProperty(nameof(Filters));
model.ItemsChanged += Model_ItemsChanged;
FetchItems(true);
model.ItemsChanged += Model_ItemsChanged;
}
private static IGridPropertiesViewModel? LoadGridPropertiesViewModel(IGridProperties? gridProperties)

View File

@@ -135,7 +135,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
private void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw e.Exception;
throw e.Exception ?? new InvalidOperationException(
$"Navigation to {e.SourcePageType?.FullName ?? "unknown page"} failed.");
}
private void Frame_Navigated(object sender, NavigationEventArgs e)