-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathSidebarItem.cs
More file actions
620 lines (559 loc) · 21.3 KB
/
Copy pathSidebarItem.cs
File metadata and controls
620 lines (559 loc) · 21.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
using CommunityToolkit.WinUI;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Runtime.InteropServices;
using Windows.ApplicationModel.DataTransfer;
using Windows.Storage;
namespace Files.App.Controls
{
public sealed partial class SidebarItem : Control
{
private const double DROP_REPOSITION_THRESHOLD = 0.2; // Percentage of top/bottom at which we consider a drop to be a reposition/insertion
public bool HasChildren => (Item?.Children is IList enumerable && enumerable.Count > 0) || (Item?.HasUnrealizedChildren ?? false);
public bool IsGroupHeader => Item?.Children is not null;
public bool CollapseEnabled => DisplayMode != SidebarDisplayMode.Compact;
private bool hasChildSelection => selectedChildItem != null;
private bool isPointerOver = false;
private bool isClicking = false;
private object? selectedChildItem = null;
private ISidebarItemModel? lastSubscriber;
// Owner DisplayMode callback runs once per container, gated by isWiredUp. Template-child handlers (ElementBorder pointer events etc.) run once per template application, gated by isTemplateWired — they can't share the gate because Loaded can fire on a Visibility=Collapsed container before OnApplyTemplate has supplied any template children to hook up.
private bool isWiredUp;
private bool isTemplateWired;
private DispatcherQueueTimer? dragOverTimer;
private DispatcherQueueTimer? dragOverExpandTimer;
private SidebarItemDropPosition lastDropPosition = SidebarItemDropPosition.Center;
public SidebarItem()
{
DefaultStyleKey = typeof(SidebarItem);
PointerReleased += Item_PointerReleased;
KeyDown += (sender, args) =>
{
switch (args.Key)
{
case Windows.System.VirtualKey.Enter:
Clicked(PointerUpdateKind.Other);
args.Handled = true;
break;
case Windows.System.VirtualKey.Right when HasChildren && CollapseEnabled && !IsExpanded:
IsExpanded = true;
args.Handled = true;
break;
case Windows.System.VirtualKey.Left when HasChildren && CollapseEnabled && IsExpanded:
IsExpanded = false;
args.Handled = true;
break;
}
};
DragStarting += SidebarItem_DragStarting;
Loaded += SidebarItem_Loaded;
}
protected override AutomationPeer OnCreateAutomationPeer()
{
return new SidebarItemAutomationPeer(this);
}
// Template-tied work needs to run *here* (not in Loaded) because Loaded can fire while the control is still not measured; template parts may not exist yet. Sub-rows realized later would otherwise keep isWiredUp=true with no handlers attached.
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
if (!isTemplateWired)
{
isTemplateWired = true;
if (GetTemplateChild("ElementBorder") is Border border)
{
border.PointerEntered += ItemBorder_PointerEntered;
border.PointerExited += ItemBorder_PointerExited;
border.PointerCanceled += ItemBorder_PointerCanceled;
border.PointerPressed += ItemBorder_PointerPressed;
border.ContextRequested += ItemBorder_ContextRequested;
border.DoubleTapped += ItemBorder_DoubleTapped;
border.DragLeave += ItemBorder_DragLeave;
border.DragOver += ItemBorder_DragOver;
border.Drop += ItemBorder_Drop;
border.AllowDrop = true;
border.IsTabStop = false;
}
if (GetTemplateChild("ChevronContainer") is Border chevronContainer)
chevronContainer.PointerPressed += ChevronContainer_PointerPressed;
if (GetTemplateChild("FlyoutChildrenPresenter") is ItemsRepeater flyoutRepeater)
flyoutRepeater.ElementPrepared += FlyoutChildrenPresenter_ElementPrepared;
}
if (Owner is null)
return;
VisualStateManager.GoToState(this, Owner.SupportsExpansion ? "OwnerSupportsExpansion" : "OwnerDoesNotSupportExpansion", false);
// Flyout items inherit DisplayMode=Compact from the parent SidebarView but render full-size inside the overlay; they must NOT enter the Compact visual state or their text gets hidden. This matches the !IsInFlyout guard in SidebarDisplayModeChanged.
if (!IsInFlyout)
VisualStateManager.GoToState(this, DisplayMode == SidebarDisplayMode.Compact ? "Compact" : "NonCompact", false);
UpdateExpansionState();
}
internal void Select()
{
if (Owner is not null)
Owner.SelectedItem = Item!;
}
private void SidebarItem_Loaded(object sender, RoutedEventArgs e)
{
// Loaded fires every time ItemsRepeater recycles the container; only the per-row HandleItemChange runs each time.
if (!isWiredUp)
{
HookupOwners();
// HookupOwners can leave Owner null for static SidebarItems whose FindAscendant walk fires before they're parented into a SidebarView (rare). Leave isWiredUp=false so the next Loaded retries.
if (Owner is not null)
isWiredUp = true;
}
HandleItemChange();
}
public void HandleItemChange()
{
HookupItemChangeListener(null, Item);
UpdateExpansionState();
ReevaluateSelection();
if (Item is not null)
{
CanDrag = IsValidDropPath(Item.Path);
UseReorderDrop = !IsGroupHeader && CanDrag && Item.IsReorderDropItem;
}
else
{
CanDrag = false;
UseReorderDrop = false;
}
}
private void HookupOwners()
{
// Owner is pushed in by the hosting SidebarView's MenuItemsHost_ElementPrepared (top-level rows) or the parent SidebarItem's FlyoutChildrenPresenter_ElementPrepared (flyout children) before Loaded fires. Static SidebarItems declared directly in XAML (MainPage's SettingsButton in SidebarView.Footer) aren't realized through either path, so resolve Owner via a visual-tree walk for them. OwnerExpansionSupport state is applied by OnOwnerChanged.
if (Owner is null)
Owner = this.FindAscendant<SidebarView>();
if (Owner is null)
return;
Owner.RegisterPropertyChangedCallback(SidebarView.DisplayModeProperty, (sender, args) =>
{
DisplayMode = Owner.DisplayMode;
});
DisplayMode = Owner.DisplayMode;
// Setting the DP above only fires SidebarDisplayModeChanged (which calls GoToState) when the value actually changes from the default — sub-rows realized after Compact→Expanded never trigger it because both default and new value are Expanded. Force the state transition. Flyout items are skipped (same as in SidebarDisplayModeChanged) so they don't enter Compact and hide their text.
if (!IsInFlyout)
VisualStateManager.GoToState(this, DisplayMode == SidebarDisplayMode.Compact ? "Compact" : "NonCompact", false);
// Static SidebarItems (MainPage's SettingsButton inside SidebarView.Footer) sit outside MenuItemsHost, so SidebarView.OnSelectedItemChanged's broadcast can't reach them. The per-row callback fills that gap.
Owner.RegisterPropertyChangedCallback(SidebarView.SelectedItemProperty, (sender, args) =>
{
ReevaluateSelection();
});
}
private void HookupItemChangeListener(ISidebarItemModel? oldItem, ISidebarItemModel? newItem)
{
if (lastSubscriber != null)
{
if (lastSubscriber.Children is INotifyCollectionChanged observableCollection)
observableCollection.CollectionChanged -= ChildItems_CollectionChanged;
lastSubscriber.PropertyChanged -= Item_PropertyChanged;
}
if (oldItem != null)
{
if (oldItem.Children is INotifyCollectionChanged observableCollection)
observableCollection.CollectionChanged -= ChildItems_CollectionChanged;
oldItem.PropertyChanged -= Item_PropertyChanged;
}
if (newItem != null)
{
lastSubscriber = newItem;
if (newItem.Children is INotifyCollectionChanged observableCollection)
observableCollection.CollectionChanged += ChildItems_CollectionChanged;
newItem.PropertyChanged += Item_PropertyChanged;
}
}
private void Item_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(ISidebarItemModel.HasUnrealizedChildren):
case nameof(ISidebarItemModel.IsLeafWithChildren):
case nameof(ISidebarItemModel.Children):
UpdateExpansionState();
ReevaluateSelection();
break;
}
}
private static bool IsValidDropPath(string? path)
=> path is not null && (System.IO.Path.IsPathRooted(path) || path.StartsWith("Shell:", StringComparison.OrdinalIgnoreCase));
private void SidebarItem_DragStarting(UIElement sender, DragStartingEventArgs args)
{
if (Item?.Path is not string dragPath || !IsValidDropPath(dragPath))
return;
SafetyExtensions.IgnoreExceptions(() =>
{
args.Data.SetData(StandardDataFormats.Text, dragPath);
args.Data.RequestedOperation = DataPackageOperation.Move | DataPackageOperation.Copy | DataPackageOperation.Link;
args.Data.SetDataProvider(StandardDataFormats.StorageItems, async request =>
{
var deferral = SafetyExtensions.IgnoreExceptions(() => request.GetDeferral(), null, typeof(COMException));
try
{
if (Directory.Exists(dragPath))
{
var folder = await StorageFolder.GetFolderFromPathAsync(dragPath);
request.SetData(new IStorageItem[] { folder });
}
}
finally
{
if (deferral is not null)
SafetyExtensions.IgnoreExceptions(() => deferral.Complete(), null, typeof(COMException));
}
});
}, null, typeof(COMException));
}
private void SetFlyoutOpen(bool isOpen = true)
{
if (Item?.Children is null) return;
var flyoutOwner = (GetTemplateChild("ElementGrid") as FrameworkElement)!;
try
{
if (isOpen)
{
FlyoutBase.ShowAttachedFlyout(flyoutOwner);
}
else
{
FlyoutBase.GetAttachedFlyout(flyoutOwner).Hide();
}
}
// ArgumentException when GetAttachedFlyout/ShowAttachedFlyout runs before the template is applied (e.g. DisplayMode toggled via ToggleSidebarAction at startup, before all containers have realized).
catch (ArgumentException) { }
}
private void ChildItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
ReevaluateSelection();
UpdateExpansionState();
if (DisplayMode == SidebarDisplayMode.Compact && !HasChildren)
{
SetFlyoutOpen(false);
}
}
// Entry point for SidebarView's SelectedItem PropertyChangedCallback to broadcast selection changes to every realized row, bypassing the per-row RegisterPropertyChangedCallback (which only attaches after Loaded).
internal void ReevaluateSelectionFromOwner() => ReevaluateSelection();
private void ReevaluateSelection()
{
// Leaves-with-children (tree-view folder rows) can be selected themselves as well as host a selected descendant.
var isLeafWithChildren = Item?.IsLeafWithChildren == true;
var selected = Owner?.SelectedItem;
if (!IsGroupHeader || isLeafWithChildren)
{
// Item-null guard avoids the null==null match that paints cleared/recycled containers as selected when SelectedItem is also null (e.g. after collapsing the section that held the active path).
IsSelected = Item is not null && Item == selected;
if (IsSelected)
{
Owner?.UpdateSelectedItemContainer(this);
}
}
else
{
// Recycled container previously bound to a selected leaf carries IsSelected=true into its new section-header binding; left unset, the header paints selected alongside the actual selected row after Compact↔overlay flips rebuild the flat list.
IsSelected = false;
}
if (IsGroupHeader && Item?.Children is IList list && selected is not null && list.Contains(selected))
{
selectedChildItem = selected;
SetFlyoutOpen(false);
}
else
{
selectedChildItem = null;
}
UpdateSelectionState();
}
// Flyout items live outside the flat list and need their selection state mirrored here so the realized row matches what the inline row would render.
private void FlyoutChildrenPresenter_ElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args)
{
if (args.Element is SidebarItem item && Item?.Children is IList enumerable)
{
// Inherit the owning SidebarView so the flyout row's click routes to the correct view's RaiseItemInvoked instead of falling through to a FindAscendant walk that — inside a popup-hosted ItemsRepeater — can resolve to the wrong SidebarView entirely.
item.Owner = Owner;
var newElement = enumerable[args.Index];
item.IsSelected = newElement == selectedChildItem;
item.HandleItemChange();
}
}
internal void Clicked(PointerUpdateKind pointerUpdateKind)
{
// Section headers (Pinned, Drives, ...) toggle expansion on row click since they have no navigation target. Tree-view folder rows (leaves-with-children) only navigate — their expansion is reserved for the chevron click target.
if (IsGroupHeader && Item?.IsLeafWithChildren != true)
{
if (CollapseEnabled)
{
IsExpanded = !IsExpanded;
}
else if (HasChildren)
{
SetFlyoutOpen(true);
}
}
RaiseItemInvoked(pointerUpdateKind);
}
// Chevron press: suppress the bubbling press; otherwise ElementBorder treats the chevron click as a row click and raises ItemInvoked.
private void ChevronContainer_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
=> e.Handled = TryToggleExpansion();
private void ItemBorder_DoubleTapped(object sender, Microsoft.UI.Xaml.Input.DoubleTappedRoutedEventArgs e)
=> e.Handled = TryToggleExpansion();
private bool TryToggleExpansion()
{
if (!HasChildren || !CollapseEnabled)
return false;
IsExpanded = !IsExpanded;
return true;
}
internal void RaiseItemInvoked(PointerUpdateKind pointerUpdateKind)
{
Owner?.RaiseItemInvoked(this, pointerUpdateKind);
}
private void SidebarDisplayModeChanged(SidebarDisplayMode oldValue)
{
switch (DisplayMode)
{
case SidebarDisplayMode.Expanded:
UpdateExpansionState();
UpdateSelectionState();
SetFlyoutOpen(false);
break;
case SidebarDisplayMode.Minimal:
UpdateExpansionState();
SetFlyoutOpen(false);
break;
case SidebarDisplayMode.Compact:
UpdateExpansionState();
UpdateSelectionState();
break;
}
if (!IsInFlyout)
{
VisualStateManager.GoToState(this, DisplayMode == SidebarDisplayMode.Compact ? "Compact" : "NonCompact", false);
}
}
private void UpdateSelectionState()
{
// Containers re-bind constantly during fast scroll; play state changes without transitions so no implicit animations fire on each ItemsRepeater realization.
VisualStateManager.GoToState(this, ShouldShowSelectionIndicator() ? "Selected" : "Unselected", false);
UpdatePointerState();
}
private bool ShouldShowSelectionIndicator()
{
if (IsExpanded && CollapseEnabled)
{
return IsSelected;
}
else
{
return IsSelected || hasChildSelection;
}
}
private void UpdatePointerState(bool isPointerDown = false)
{
var useSelectedState = ShouldShowSelectionIndicator();
if (isPointerDown)
{
VisualStateManager.GoToState(this, useSelectedState ? "PressedSelected" : "Pressed", false);
}
else if (isPointerOver)
{
VisualStateManager.GoToState(this, useSelectedState ? "PointerOverSelected" : "PointerOver", false);
}
else
{
VisualStateManager.GoToState(this, useSelectedState ? "NormalSelected" : "Normal", false);
}
}
private void UpdateExpansionState()
{
if (Owner?.SupportsExpansion == false)
{
VisualStateManager.GoToState(this, "NoExpansion", false);
UpdateSelectionState();
return;
}
if (Item?.Children is null || !CollapseEnabled)
{
VisualStateManager.GoToState(this, "NoExpansion", false);
}
else if (!HasChildren)
{
// Empty folder leaves render like normal leaves; empty group headers keep the section-heading style.
VisualStateManager.GoToState(this, Item?.IsLeafWithChildren == true ? "NoExpansion" : "NoChildren", false);
}
else
{
VisualStateManager.GoToState(this, Item?.IsLeafWithChildren == true ? "LeafWithChildren" : (IsExpanded ? "Expanded" : "Collapsed"), false);
VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconNormal" : "CollapsedIconNormal", false);
}
UpdateSelectionState();
}
private void ItemBorder_PointerEntered(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
isPointerOver = true;
UpdatePointerState();
}
private void ItemBorder_PointerExited(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
isPointerOver = false;
isClicking = false;
UpdatePointerState();
}
private void ItemBorder_PointerCanceled(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
isClicking = false;
UpdatePointerState();
}
private void ItemBorder_PointerPressed(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
isClicking = true;
UpdatePointerState(true);
VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconPressed" : "CollapsedIconPressed", true);
}
private void Item_PointerReleased(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e)
{
if (!isClicking)
return;
isClicking = false;
e.Handled = true;
UpdatePointerState();
VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconNormal" : "CollapsedIconNormal", true);
var pointerUpdateKind = e.GetCurrentPoint(null).Properties.PointerUpdateKind;
if (pointerUpdateKind == PointerUpdateKind.LeftButtonReleased ||
pointerUpdateKind == PointerUpdateKind.MiddleButtonReleased)
{
Clicked(pointerUpdateKind);
}
}
private async void ItemBorder_DragOver(object sender, DragEventArgs e)
{
// Expected to fail with COMException if the OLE drag payload is stale
var deferral = SafetyExtensions.IgnoreExceptions(() => e.GetDeferral(), null, typeof(COMException));
try
{
var dropPosition = DetermineDropTargetPosition(e);
if (Owner is not null)
Owner.RaiseItemDragOver(this, dropPosition, e);
bool isHandled = false;
DataPackageOperation acceptedOperation = DataPackageOperation.None;
var propertiesRead = SafetyExtensions.IgnoreExceptions(() =>
{
isHandled = e.Handled;
acceptedOperation = e.AcceptedOperation;
}, null, typeof(COMException));
if (dropPosition != lastDropPosition)
{
acceptedOperation = DataPackageOperation.None;
}
lastDropPosition = dropPosition;
if (!propertiesRead || !isHandled || acceptedOperation == DataPackageOperation.None)
{
VisualStateManager.GoToState(this, "Normal", true);
return;
}
if (dropPosition == SidebarItemDropPosition.Center)
{
VisualStateManager.GoToState(this, "DragOnTop", true);
}
else if (dropPosition == SidebarItemDropPosition.Top)
{
VisualStateManager.GoToState(this, "DragInsertAbove", true);
}
else if (dropPosition == SidebarItemDropPosition.Bottom)
{
VisualStateManager.GoToState(this, "DragInsertBelow", true);
}
var openDelay = Owner?.HoverToOpenDelay ?? TimeSpan.Zero;
var expandDelay = Owner?.HoverToExpandDelay ?? TimeSpan.Zero;
var isCenter = dropPosition == SidebarItemDropPosition.Center;
var canHoverOpen = openDelay > TimeSpan.Zero && isCenter && Item is not null && (!IsGroupHeader || Item.IsLeafWithChildren);
var canHoverExpand = expandDelay > TimeSpan.Zero && isCenter && HasChildren && CollapseEnabled;
if (canHoverExpand)
{
dragOverExpandTimer ??= DispatcherQueue.CreateTimer();
dragOverExpandTimer.Debounce(
() =>
{
dragOverExpandTimer!.Stop();
IsExpanded = true;
},
expandDelay,
false);
}
else
{
dragOverExpandTimer?.Stop();
}
if (canHoverOpen)
{
dragOverTimer ??= DispatcherQueue.CreateTimer();
dragOverTimer.Debounce(
() =>
{
dragOverTimer!.Stop();
RaiseItemInvoked(PointerUpdateKind.Other);
},
openDelay,
false);
}
else
{
dragOverTimer?.Stop();
}
}
finally
{
if (deferral is not null)
SafetyExtensions.IgnoreExceptions(() => deferral.Complete(), null, typeof(COMException));
}
}
private void ItemBorder_ContextRequested(UIElement sender, Microsoft.UI.Xaml.Input.ContextRequestedEventArgs args)
{
Owner?.RaiseContextRequested(this, args.TryGetPosition(this, out var point) ? point : default);
args.Handled = true;
}
private void ItemBorder_DragLeave(object sender, DragEventArgs e)
{
dragOverTimer?.Stop();
dragOverExpandTimer?.Stop();
lastDropPosition = SidebarItemDropPosition.Center;
UpdatePointerState();
}
private void ItemBorder_Drop(object sender, DragEventArgs e)
{
dragOverTimer?.Stop();
dragOverExpandTimer?.Stop();
lastDropPosition = SidebarItemDropPosition.Center;
UpdatePointerState();
Owner?.RaiseItemDropped(this, DetermineDropTargetPosition(e), e);
}
private SidebarItemDropPosition DetermineDropTargetPosition(DragEventArgs args)
{
if (UseReorderDrop)
{
if (GetTemplateChild("ElementGrid") is Grid grid)
{
var position = args.GetPosition(grid);
if (position.Y < grid.ActualHeight * DROP_REPOSITION_THRESHOLD)
{
return SidebarItemDropPosition.Top;
}
if (position.Y > grid.ActualHeight * (1 - DROP_REPOSITION_THRESHOLD))
{
return SidebarItemDropPosition.Bottom;
}
return SidebarItemDropPosition.Center;
}
}
return SidebarItemDropPosition.Center;
}
}
}