Skip to content

Commit 04db724

Browse files
committed
Fixed crash related to CommandBarFlyout
1 parent 50a0108 commit 04db724

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

src/Files.App/App.xaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using CommunityToolkit.WinUI;
33
using CommunityToolkit.WinUI.Helpers;
44
using CommunityToolkit.WinUI.Notifications;
5-
using Files.App.Controllers;
65
using Files.App.DataModels;
76
using Files.App.Extensions;
87
using Files.App.Filesystem;
@@ -30,6 +29,7 @@
3029
using Microsoft.Extensions.DependencyInjection;
3130
using Microsoft.UI.Windowing;
3231
using Microsoft.UI.Xaml;
32+
using Microsoft.UI.Xaml.Controls;
3333
using Microsoft.Windows.AppLifecycle;
3434
using System;
3535
using System.Diagnostics;
@@ -54,6 +54,7 @@ public partial class App : Application
5454
private static bool ShowErrorNotification = false;
5555

5656
public static string OutputPath { get; set; }
57+
public static CommandBarFlyout? LastOpenedFlyout { get; set; }
5758
public static StorageHistoryWrapper HistoryWrapper = new StorageHistoryWrapper();
5859
public static SettingsViewModel AppSettings { get; private set; }
5960
public static AppModel AppModel { get; private set; }
@@ -287,6 +288,15 @@ private async void Window_Closed(object sender, WindowEventArgs args)
287288
{
288289
// Save application state and stop any background activity
289290

291+
// A Workaround for the crash (#10110)
292+
if (LastOpenedFlyout?.IsOpen ?? false)
293+
{
294+
args.Handled = true;
295+
LastOpenedFlyout.Closed += (sender, e) => App.Current.Exit();
296+
LastOpenedFlyout.Hide();
297+
return;
298+
}
299+
290300
await Task.Yield(); // Method can take a long time, make sure the window is hidden
291301

292302
SaveSessionTabs();

src/Files.App/BaseLayout.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
556556

557557
public async void ItemContextFlyout_Opening(object? sender, object e)
558558
{
559+
App.LastOpenedFlyout = sender as CommandBarFlyout;
560+
559561
try
560562
{
561563
if (!IsItemSelected && ((sender as CommandBarFlyout)?.Target as ListViewItem)?.Content is ListedItem li) // Workaround for item sometimes not getting selected
@@ -574,6 +576,8 @@ public async void ItemContextFlyout_Opening(object? sender, object e)
574576

575577
public async void BaseContextFlyout_Opening(object? sender, object e)
576578
{
579+
App.LastOpenedFlyout = sender as CommandBarFlyout;
580+
577581
try
578582
{
579583
// Reset menu max height

src/Files.App/UserControls/SidebarControl.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ private void PaneRoot_RightTapped(object sender, RightTappedRoutedEventArgs e)
420420
private void NavigationViewItem_RightTapped(object sender, RightTappedRoutedEventArgs e)
421421
{
422422
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
423+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
423424
if (sender is not NavigationViewItem sidebarItem ||
424425
sidebarItem.DataContext is not INavigationControlItem item)
425426
return;

src/Files.App/UserControls/Widgets/FileTagsWidget.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private async void FileTagItem_ItemClick(object sender, ItemClickEventArgs e)
6565
private void Item_RightTapped(object sender, RightTappedRoutedEventArgs e)
6666
{
6767
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
68+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
6869
if (sender is not StackPanel tagsItemsStackPanel || tagsItemsStackPanel.DataContext is not FileTagsItemViewModel item)
6970
return;
7071
itemContextMenuFlyout.ShowAt(tagsItemsStackPanel, new FlyoutShowOptions { Position = e.GetPosition(tagsItemsStackPanel) });

src/Files.App/UserControls/Widgets/HomePageWidget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public abstract class HomePageWidget : UserControl
4747
public void Button_RightTapped(object sender, RightTappedRoutedEventArgs e)
4848
{
4949
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
50+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
5051
if (sender is not Button widgetCardItem || widgetCardItem.DataContext is not WidgetCardItem item)
5152
return;
5253

src/Files.App/UserControls/Widgets/RecentFilesWidget.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public RecentFilesWidget()
109109
private void Grid_RightTapped(object sender, RightTappedRoutedEventArgs e)
110110
{
111111
var itemContextMenuFlyout = new CommandBarFlyout { Placement = FlyoutPlacementMode.Full };
112+
itemContextMenuFlyout.Opening += (sender, e) => App.LastOpenedFlyout = sender as CommandBarFlyout;
112113
if (sender is not Grid recentItemsGrid || recentItemsGrid.DataContext is not RecentItem item)
113114
return;
114115

0 commit comments

Comments
 (0)