Skip to content

Commit 51bde0e

Browse files
committed
Fix Quirky PhotoAlbum Layout Right Click Behavior
1 parent 0525252 commit 51bde0e

File tree

3 files changed

+72
-49
lines changed

3 files changed

+72
-49
lines changed

Files UWP/FilesUWP.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@
258258
<PackageReference Include="Microsoft.UI.Xaml">
259259
<Version>2.1.190405004.2</Version>
260260
</PackageReference>
261+
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed">
262+
<Version>2.0.1</Version>
263+
</PackageReference>
261264
</ItemGroup>
262265
<ItemGroup>
263266
<SDKReference Include="WindowsDesktop, Version=10.0.18362.0">

Files UWP/PhotoAlbum.xaml

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1010
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
1111
xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
12+
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
13+
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
1214
mc:Ignorable="d"
1315
xmlns:navigation="using:Files.Navigation"
1416
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
@@ -403,56 +405,62 @@
403405
<ProgressBar Name="ProgBar" Height="10" VerticalAlignment="Top" IsIndeterminate="True"/>
404406
<TextBlock Visibility="{x:Bind TextState.isVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Name="EmptyText" HorizontalAlignment="Center" Text="This folder is empty." TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,125,0,0" Grid.Row="3" Canvas.ZIndex="0"/>
405407

406-
<GridView ContextRequested="FileList_ContextRequested" Background="Transparent" ItemsSource="{x:Bind instanceViewModel.FilesAndFolders}" RightTapped="FileList_RightTapped" VerticalContentAlignment="Stretch" animations:ReorderGridAnimation.Duration="300" ShowsScrollingPlaceholders="True" Margin="24,24,24,0" Grid.Row="3" SelectionMode="Extended" IsRightTapEnabled="True" IsDoubleTapEnabled="True" Name="FileList" Padding="0, 0, 0, 0" >
407-
<GridView.ContextFlyout>
408-
<MenuFlyout x:Name="RightClickContextMenu" MenuFlyoutPresenterStyle="{StaticResource MenuFlyoutFluentThemeResources}">
409-
<MenuFlyout.Items>
410-
<MenuFlyoutItem Click="OpenItem_Click" Text="Open With..." Name="OpenItem">
411-
<MenuFlyoutItem.Icon>
412-
<FontIcon Glyph="&#xE7AC;"/>
413-
</MenuFlyoutItem.Icon>
414-
</MenuFlyoutItem>
415-
<MenuFlyoutItem Click="ShareItem_Click" Text="Share" Name="ShareItem">
416-
<MenuFlyoutItem.Icon>
417-
<FontIcon Glyph="&#xE72D;"/>
418-
</MenuFlyoutItem.Icon>
419-
</MenuFlyoutItem>
420-
<MenuFlyoutSeparator/>
421-
<MenuFlyoutItem Click="DeleteItem_Click" Text="Delete" Name="DeleteItem" >
422-
<MenuFlyoutItem.Icon>
423-
<FontIcon Glyph="&#xE74D;"/>
424-
</MenuFlyoutItem.Icon>
425-
</MenuFlyoutItem>
426-
<MenuFlyoutItem Click="RenameItem_Click" Text="Rename" Name="RenameItem" >
427-
<MenuFlyoutItem.Icon>
428-
<FontIcon Glyph="&#xE8AC;"/>
429-
</MenuFlyoutItem.Icon>
430-
</MenuFlyoutItem>
431-
<MenuFlyoutSeparator/>
432-
<MenuFlyoutItem Click="CutItem_Click" Text="Cut" Name="CutItem" >
433-
<MenuFlyoutItem.Icon>
434-
<FontIcon Glyph="&#xE8C6;"/>
435-
</MenuFlyoutItem.Icon>
436-
</MenuFlyoutItem>
437-
<MenuFlyoutItem Click="CopyItem_Click" Text="Copy" Name="CopyItem" >
438-
<MenuFlyoutItem.Icon>
439-
<FontIcon Glyph="&#xE8C8;"/>
440-
</MenuFlyoutItem.Icon>
441-
</MenuFlyoutItem>
408+
<GridView Name="FileList" Margin="24,24,24,0" SelectionMode="Extended" ItemsSource="{x:Bind instanceViewModel.FilesAndFolders}" VerticalContentAlignment="Stretch" animations:ReorderGridAnimation.Duration="300">
409+
<GridView.ItemContainerStyle>
410+
<Style TargetType="GridViewItem">
411+
<Setter Property="ContextFlyout">
412+
<Setter.Value>
413+
<MenuFlyout x:Name="RightClickContextMenu" MenuFlyoutPresenterStyle="{StaticResource MenuFlyoutFluentThemeResources}">
414+
<MenuFlyout.Items>
415+
<MenuFlyoutItem Click="OpenItem_Click" Text="Open With..." Name="OpenItem">
416+
<MenuFlyoutItem.Icon>
417+
<FontIcon Glyph="&#xE7AC;"/>
418+
</MenuFlyoutItem.Icon>
419+
</MenuFlyoutItem>
420+
<MenuFlyoutItem Click="ShareItem_Click" Text="Share" Name="ShareItem">
421+
<MenuFlyoutItem.Icon>
422+
<FontIcon Glyph="&#xE72D;"/>
423+
</MenuFlyoutItem.Icon>
424+
</MenuFlyoutItem>
425+
<MenuFlyoutSeparator/>
426+
<MenuFlyoutItem Click="DeleteItem_Click" Text="Delete" Name="DeleteItem" >
427+
<MenuFlyoutItem.Icon>
428+
<FontIcon Glyph="&#xE74D;"/>
429+
</MenuFlyoutItem.Icon>
430+
</MenuFlyoutItem>
431+
<MenuFlyoutItem Click="RenameItem_Click" Text="Rename" Name="RenameItem" >
432+
<MenuFlyoutItem.Icon>
433+
<FontIcon Glyph="&#xE8AC;"/>
434+
</MenuFlyoutItem.Icon>
435+
</MenuFlyoutItem>
436+
<MenuFlyoutSeparator/>
437+
<MenuFlyoutItem Click="CutItem_Click" Text="Cut" Name="CutItem" >
438+
<MenuFlyoutItem.Icon>
439+
<FontIcon Glyph="&#xE8C6;"/>
440+
</MenuFlyoutItem.Icon>
441+
</MenuFlyoutItem>
442+
<MenuFlyoutItem Click="CopyItem_Click" Text="Copy" Name="CopyItem" >
443+
<MenuFlyoutItem.Icon>
444+
<FontIcon Glyph="&#xE8C8;"/>
445+
</MenuFlyoutItem.Icon>
446+
</MenuFlyoutItem>
442447

443-
<MenuFlyoutSeparator/>
444-
<MenuFlyoutItem Click="PropertiesItem_Click" Text="Properties" Name="PropertiesItem">
445-
<MenuFlyoutItem.Icon>
446-
<FontIcon Glyph="&#xE946;"/>
447-
</MenuFlyoutItem.Icon>
448-
</MenuFlyoutItem>
449-
</MenuFlyout.Items>
448+
<MenuFlyoutSeparator/>
449+
<MenuFlyoutItem Click="PropertiesItem_Click" Text="Properties" Name="PropertiesItem">
450+
<MenuFlyoutItem.Icon>
451+
<FontIcon Glyph="&#xE946;"/>
452+
</MenuFlyoutItem.Icon>
453+
</MenuFlyoutItem>
454+
</MenuFlyout.Items>
450455

451-
</MenuFlyout>
452-
</GridView.ContextFlyout>
456+
</MenuFlyout>
457+
</Setter.Value>
458+
</Setter>
459+
</Style>
460+
</GridView.ItemContainerStyle>
453461
<GridView.ItemTemplate>
454462
<DataTemplate x:DataType="local2:ListedItem">
455-
<StackPanel Width="150" Height="150" Tag="{x:Bind RowIndex}" Orientation="Vertical" Padding="0" ToolTipService.ToolTip="{Binding FileName}" Background="Transparent" Margin="0, 0, 0, 0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
463+
<StackPanel IsRightTapEnabled="True" RightTapped="StackPanel_RightTapped" Width="150" Height="150" Tag="{x:Bind RowIndex}" Orientation="Vertical" Padding="0" ToolTipService.ToolTip="{Binding FileName}" Background="Transparent" Margin="0, 0, 0, 0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
456464
<Grid Width="150" Height="100">
457465
<Grid Padding="12" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="Picture" Visibility="{x:Bind FileIconVis}">
458466
<Image Stretch="Uniform" Source="{x:Bind FileImg}"/>

Files UWP/PhotoAlbum.xaml.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
using System.Collections.Generic;
2020
using Windows.UI.Xaml.Data;
2121
using Windows.UI.Xaml.Controls.Primitives;
22+
using System.Windows.Input;
23+
using Microsoft.Xaml.Interactions.Core;
24+
using Microsoft.Xaml.Interactivity;
2225

2326
namespace Files
2427
{
@@ -52,7 +55,6 @@ public PhotoAlbum()
5255
Clipboard.ContentChanged += Clipboard_ContentChanged;
5356
instanceViewModel = new ItemViewModel<PhotoAlbum>(this, null);
5457
instanceInteraction = new Interaction<PhotoAlbum>(this);
55-
//gv.ItemsSource = instanceViewModel.FilesAndFolders;
5658
}
5759

5860
protected override void OnNavigatedTo(NavigationEventArgs eventArgs)
@@ -220,14 +222,23 @@ internal void TextState_PropertyChanged(object sender, PropertyChangedEventArgs
220222

221223
private void StackPanel_RightTapped(object sender, RightTappedRoutedEventArgs e)
222224
{
223-
//ObjectPressed = ((ReadOnlyObservableCollection<ListedItem>)FileList.ItemsSource)[(int)(sender as StackPanel).Tag];
225+
var parentContainer = Interaction<PhotoAlbum>.FindParent<GridViewItem>(e.OriginalSource as DependencyObject);
226+
foreach (ListedItem listedItem in FileList.SelectedItems)
227+
{
228+
if (FileList.IndexFromContainer(parentContainer) == listedItem.RowIndex)
229+
{
230+
return;
231+
}
232+
}
233+
// The following code is only reachable when a user RightTapped an unselected row
234+
FileList.SelectedItems.Clear();
235+
FileList.SelectedItems.Add(FileList.ItemFromContainer(parentContainer) as ListedItem);
224236
}
225237

226238
private void FileList_RightTapped(object sender, RightTappedRoutedEventArgs e)
227239
{
228240
try
229241
{
230-
Interaction<PhotoAlbum>.FindParent<GridViewItem>(e.OriginalSource as DependencyObject);
231242
var ItemPressed = Interaction<PhotoAlbum>.FindParent<GridViewItem>(e.OriginalSource as DependencyObject);
232243
List<StackPanel> stackPanels = new List<StackPanel>();
233244
Interaction<PhotoAlbum>.FindChildren<StackPanel>(stackPanels, ItemPressed);
@@ -251,6 +262,7 @@ private void FileList_RightTapped(object sender, RightTappedRoutedEventArgs e)
251262

252263
}
253264

265+
254266
private void FileList_ContextRequested(UIElement sender, ContextRequestedEventArgs args)
255267
{
256268

0 commit comments

Comments
 (0)