Skip to content

Commit c9aa94d

Browse files
authored
Fixed issues with sorting items from the right click context menu (#2039)
1 parent ac44d46 commit c9aa94d

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Files/Views/LayoutModes/GenericFileBrowser.xaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,46 @@
3636
</MenuFlyoutSubItem.Icon>
3737
<muxc:RadioMenuFlyoutItem
3838
x:Uid="BaseLayoutContextFlyoutSortByName"
39+
Click="RadioMenuSortColumn_Click"
3940
GroupName="SortGroup"
41+
IsChecked="{x:Bind AssociatedViewModel.IsSortedByName, Mode=TwoWay}"
42+
Tag="nameColumn"
4043
Text="Name" />
4144
<muxc:RadioMenuFlyoutItem
4245
x:Uid="BaseLayoutContextFlyoutSortByDate"
46+
Click="RadioMenuSortColumn_Click"
4347
GroupName="SortGroup"
4448
IsChecked="{x:Bind AssociatedViewModel.IsSortedByDate, Mode=TwoWay}"
49+
Tag="dateColumn"
4550
Text="Date modified" />
4651
<muxc:RadioMenuFlyoutItem
4752
x:Uid="BaseLayoutContextFlyoutSortByType"
53+
Click="RadioMenuSortColumn_Click"
4854
GroupName="SortGroup"
4955
IsChecked="{x:Bind AssociatedViewModel.IsSortedByType, Mode=TwoWay}"
56+
Tag="typeColumn"
5057
Text="Type" />
5158
<muxc:RadioMenuFlyoutItem
5259
x:Uid="BaseLayoutContextFlyoutSortBySize"
60+
Click="RadioMenuSortColumn_Click"
5361
GroupName="SortGroup"
5462
IsChecked="{x:Bind AssociatedViewModel.IsSortedBySize, Mode=TwoWay}"
63+
Tag="sizeColumn"
5564
Text="Size" />
5665
<MenuFlyoutSeparator />
5766
<muxc:RadioMenuFlyoutItem
5867
x:Uid="BaseLayoutContextFlyoutSortByAscending"
68+
Click="RadioMenuSortDirection_Click"
5969
GroupName="SortOrderGroup"
6070
IsChecked="{x:Bind AssociatedViewModel.IsSortedAscending, Mode=TwoWay}"
71+
Tag="sortAscending"
6172
Text="Ascending" />
6273
<muxc:RadioMenuFlyoutItem
6374
x:Uid="BaseLayoutContextFlyoutSortByDescending"
75+
Click="RadioMenuSortDirection_Click"
6476
GroupName="SortOrderGroup"
6577
IsChecked="{x:Bind AssociatedViewModel.IsSortedDescending, Mode=TwoWay}"
78+
Tag="sortDescending"
6679
Text="Descending" />
6780
</MenuFlyoutSubItem>
6881
<MenuFlyoutSubItem x:Uid="BaseLayoutContextFlyoutLayoutMode" Text="Layout mode">
@@ -211,34 +224,46 @@
211224
</MenuFlyoutSubItem.Icon>
212225
<muxc:RadioMenuFlyoutItem
213226
x:Uid="BaseLayoutContextFlyoutSortByName"
227+
Click="RadioMenuSortColumn_Click"
214228
GroupName="SortGroup"
215229
IsChecked="{x:Bind AssociatedViewModel.IsSortedByName, Mode=TwoWay}"
230+
Tag="nameColumn"
216231
Text="Name" />
217232
<muxc:RadioMenuFlyoutItem
218233
x:Uid="BaseLayoutContextFlyoutSortByDate"
234+
Click="RadioMenuSortColumn_Click"
219235
GroupName="SortGroup"
220236
IsChecked="{x:Bind AssociatedViewModel.IsSortedByDate, Mode=TwoWay}"
237+
Tag="dateColumn"
221238
Text="Date modified" />
222239
<muxc:RadioMenuFlyoutItem
223240
x:Uid="BaseLayoutContextFlyoutSortByType"
241+
Click="RadioMenuSortColumn_Click"
224242
GroupName="SortGroup"
225243
IsChecked="{x:Bind AssociatedViewModel.IsSortedByType, Mode=TwoWay}"
244+
Tag="typeColumn"
226245
Text="Type" />
227246
<muxc:RadioMenuFlyoutItem
228247
x:Uid="BaseLayoutContextFlyoutSortBySize"
248+
Click="RadioMenuSortColumn_Click"
229249
GroupName="SortGroup"
230250
IsChecked="{x:Bind AssociatedViewModel.IsSortedBySize, Mode=TwoWay}"
251+
Tag="sizeColumn"
231252
Text="Size" />
232253
<MenuFlyoutSeparator />
233254
<muxc:RadioMenuFlyoutItem
234255
x:Uid="BaseLayoutContextFlyoutSortByAscending"
256+
Click="RadioMenuSortDirection_Click"
235257
GroupName="SortOrderGroup"
236258
IsChecked="{x:Bind AssociatedViewModel.IsSortedAscending, Mode=TwoWay}"
259+
Tag="sortAscending"
237260
Text="Ascending" />
238261
<muxc:RadioMenuFlyoutItem
239262
x:Uid="BaseLayoutContextFlyoutSortByDescending"
263+
Click="RadioMenuSortDirection_Click"
240264
GroupName="SortOrderGroup"
241265
IsChecked="{x:Bind AssociatedViewModel.IsSortedDescending, Mode=TwoWay}"
266+
Tag="sortDescending"
242267
Text="Descending" />
243268
</MenuFlyoutSubItem>
244269
<MenuFlyoutItem

Files/Views/LayoutModes/GenericFileBrowser.xaml.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Files.Helpers;
44
using Microsoft.Toolkit.Uwp.UI;
55
using Microsoft.Toolkit.Uwp.UI.Controls;
6+
using Microsoft.UI.Xaml.Controls;
67
using System;
78
using System.Collections;
89
using System.Collections.Generic;
@@ -457,5 +458,46 @@ protected override ListedItem GetItemFromElement(object element)
457458
DataGridRow row = element as DataGridRow;
458459
return row.DataContext as ListedItem;
459460
}
461+
462+
private void RadioMenuSortColumn_Click(object sender, RoutedEventArgs e)
463+
{
464+
DataGridColumnEventArgs args = null;
465+
466+
switch ((sender as RadioMenuFlyoutItem).Tag)
467+
{
468+
case "nameColumn":
469+
args = new DataGridColumnEventArgs(nameColumn);
470+
break;
471+
472+
case "dateColumn":
473+
args = new DataGridColumnEventArgs(dateColumn);
474+
break;
475+
476+
case "typeColumn":
477+
args = new DataGridColumnEventArgs(typeColumn);
478+
break;
479+
480+
case "sizeColumn":
481+
args = new DataGridColumnEventArgs(sizeColumn);
482+
break;
483+
}
484+
485+
if (args != null)
486+
{
487+
AllView_Sorting(sender, args);
488+
}
489+
}
490+
491+
private void RadioMenuSortDirection_Click(object sender, RoutedEventArgs e)
492+
{
493+
if (((sender as RadioMenuFlyoutItem).Tag as string) == "sortAscending")
494+
{
495+
SortedColumn.SortDirection = DataGridSortDirection.Ascending;
496+
}
497+
else if (((sender as RadioMenuFlyoutItem).Tag as string) == "sortDescending")
498+
{
499+
SortedColumn.SortDirection = DataGridSortDirection.Descending;
500+
}
501+
}
460502
}
461503
}

Files/Views/LayoutModes/GridViewBrowser.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<muxc:RadioMenuFlyoutItem
3434
x:Uid="BaseLayoutContextFlyoutSortByName"
3535
GroupName="SortGroup"
36+
IsChecked="{x:Bind AssociatedViewModel.IsSortedByName, Mode=TwoWay}"
3637
Text="Name" />
3738
<muxc:RadioMenuFlyoutItem
3839
x:Uid="BaseLayoutContextFlyoutSortByDate"

0 commit comments

Comments
 (0)