Skip to content

Commit bd99b46

Browse files
authored
Alt approach
1 parent 720778c commit bd99b46

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using CommunityToolkit.WinUI.UI;
55
using Microsoft.UI.Xaml;
66
using Microsoft.UI.Xaml.Controls;
7+
using Microsoft.UI.Xaml.Input;
78
using Microsoft.UI.Xaml.Shapes;
89
using Windows.ApplicationModel.DataTransfer;
910
using Windows.Storage;
@@ -142,7 +143,6 @@ private void TabHoverSelected(object sender, object e)
142143

143144
private void TabView_TabDragStarting(TabView sender, TabViewTabDragStartingEventArgs args)
144145
{
145-
cancelTagDrag = false;
146146
var tabViewItemArgs = (args.Item as TabBarItem).NavigationParameter;
147147
args.Data.Properties.Add(TabPathIdentifier, tabViewItemArgs.Serialize());
148148
args.Data.RequestedOperation = DataPackageOperation.Move;
@@ -152,14 +152,14 @@ private void TabView_TabDragStarting(TabView sender, TabViewTabDragStartingEvent
152152

153153
// Force focus in order that the keydown event works
154154
Focus(FocusState.Programmatic);
155-
PreviewKeyDown += (s, e) =>
156-
{
157-
if (e.Key is Windows.System.VirtualKey.Escape)
158-
{
159-
args.Cancel = true;
160-
cancelTagDrag = true;
161-
}
162-
};
155+
cancelTagDrag = false;
156+
PreviewKeyDown += DraggingKeyDown;
157+
}
158+
159+
private void DraggingKeyDown(object sender, KeyRoutedEventArgs e)
160+
{
161+
if (e.Key is Windows.System.VirtualKey.Escape)
162+
cancelTagDrag = true;
163163
}
164164

165165
private void TabView_TabStripDragOver(object sender, DragEventArgs e)
@@ -217,9 +217,6 @@ private async void TabView_TabStripDrop(object sender, DragEventArgs e)
217217

218218
private void TabView_TabDragCompleted(TabView sender, TabViewTabDragCompletedEventArgs args)
219219
{
220-
if (cancelTagDrag)
221-
return;
222-
223220
if (ApplicationData.Current.LocalSettings.Values.ContainsKey(TabDropHandledIdentifier) &&
224221
(bool)ApplicationData.Current.LocalSettings.Values[TabDropHandledIdentifier])
225222
{
@@ -234,10 +231,14 @@ private void TabView_TabDragCompleted(TabView sender, TabViewTabDragCompletedEve
234231
{
235232
ApplicationData.Current.LocalSettings.Values.Remove(TabDropHandledIdentifier);
236233
}
234+
235+
PreviewKeyDown -= DraggingKeyDown;
237236
}
238237

239238
private async void TabView_TabDroppedOutside(TabView sender, TabViewTabDroppedOutsideEventArgs args)
240239
{
240+
PreviewKeyDown -= DraggingKeyDown;
241+
241242
if (cancelTagDrag)
242243
return;
243244

0 commit comments

Comments
 (0)