Skip to content

Commit e2d2882

Browse files
committed
Improved Right-Click Context Menu
1 parent c7dfc4a commit e2d2882

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

FileLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ListedItem
3838
public string FileDate { get; set; }
3939
public string FileExtension { get; set; }
4040
public string FilePath { get; set; }
41+
public int ItemIndex { get; set; }
4142
public ListedItem()
4243
{
4344

@@ -230,7 +231,7 @@ public async void GetItemsAsync(string path)
230231
gotFolType = "Folder";
231232
gotFolImg = Visibility.Visible;
232233
gotFileImgVis = Visibility.Collapsed;
233-
FilesAndFolders.Add(new ListedItem() { FileImg = null, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotFolName, FileDate = gotFolDate, FileExtension = gotFolType, FilePath = gotFolPath });
234+
FilesAndFolders.Add(new ListedItem() { ItemIndex = FilesAndFolders.Count, FileImg = null, FileIconVis = gotFileImgVis, FolderImg = gotFolImg, FileName = gotFolName, FileDate = gotFolDate, FileExtension = gotFolType, FilePath = gotFolPath });
234235

235236
NumItemsRead++;
236237
}

Files.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
<AppxManifest Include="Package.appxmanifest">
138138
<SubType>Designer</SubType>
139139
</AppxManifest>
140-
<None Include="Files_TemporaryKey.pfx" />
141140
</ItemGroup>
142141
<ItemGroup>
143142
<Content Include="Assets\abstract_HeroImage.jpg" />
@@ -265,6 +264,9 @@
265264
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
266265
<VisualStudioVersion>14.0</VisualStudioVersion>
267266
</PropertyGroup>
267+
<PropertyGroup>
268+
<SignAssembly>true</SignAssembly>
269+
</PropertyGroup>
268270
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
269271
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
270272
Other similar extension points exist, see Microsoft.Common.targets.

GenericFileBrowser.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@
159159

160160
<Grid Padding="50,200,50,0">
161161

162-
<controls:DataGrid FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" Drop="AllView_DropAsync" AutoGenerateColumns="False" CanDrag="False" AllowDrop="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" ItemsSource="{x:Bind local2:ItemViewModel.FilesAndFolders}" Margin="0,0,0,0" Padding="0, 0, 0, 0" HorizontalAlignment="Left">
163-
164-
<controls:DataGrid.Resources>
162+
<controls:DataGrid FocusVisualPrimaryThickness="0" SelectionMode="Extended" IsDoubleTapEnabled="True" x:FieldModifier="public" x:Name="AllView" Drop="AllView_DropAsync" AutoGenerateColumns="False" CanDrag="False" AllowDrop="True" DragOver="AllView_DragOver" IsRightTapEnabled="True" CanUserReorderColumns="False" IsReadOnly="True" ItemsSource="{x:Bind local2:ItemViewModel.FilesAndFolders}" Margin="0,0,0,0" Padding="0, 0, 0, 0" HorizontalAlignment="Left">
163+
164+
<controls:DataGrid.Resources>
165165
<MenuFlyout x:Name="HeaderRightClickMenu" x:Key="HeaderRightClickFlyout">
166166
<MenuFlyoutItem Text="Edit Columns" Name="EditColumn">
167167
<MenuFlyoutItem.Icon>
@@ -174,7 +174,7 @@
174174
</MenuFlyoutItem.Icon>
175175
</MenuFlyoutItem>
176176
</MenuFlyout>
177-
177+
178178
<MenuFlyout x:Name="RightClickContextMenu" x:Key="RightClickFlyout">
179179
<MenuFlyout.Items>
180180
<MenuFlyoutItem Text="Open" Name="OpenItem">
@@ -234,8 +234,8 @@
234234
</Setter>
235235
</Style>
236236
</controls:DataGrid.RowStyle>-->
237-
238-
<controls:DataGrid.Columns>
237+
238+
<controls:DataGrid.Columns>
239239
<controls:DataGridTemplateColumn>
240240
<controls:DataGridTemplateColumn.CellTemplate>
241241
<DataTemplate>

GenericFileBrowser.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public GenericFileBrowser()
7070
Refresh.Click += Navigation.NavigationActions.Refresh_Click;
7171
AllView.DoubleTapped += Interact.Interaction.List_ItemClick;
7272
PasteItem.Click += Interact.Interaction.PasteItem_ClickAsync;
73+
7374
}
7475

7576

ItemInteractions.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
using System.Linq;
3333
using Windows.Storage.Search;
3434
using Windows.UI.Popups;
35+
using Windows.UI.Xaml.Media;
36+
using System.Collections.ObjectModel;
3537

3638
namespace Interact
3739
{
@@ -150,21 +152,39 @@ public static async void PhotoAlbumItemList_ClickAsync(object sender, ItemClickE
150152

151153
public static void AllView_RightTapped(object sender, RightTappedRoutedEventArgs e)
152154
{
153-
154-
155155
DataGrid dataGrid = (DataGrid)sender;
156-
156+
var RowPressed = FindParent<DataGridRow>(e.OriginalSource as DependencyObject);
157+
157158
// If user clicks on header
158-
if(dataGrid.CurrentColumn == null)
159+
if (RowPressed == null)
159160
{
160161
GenericFileBrowser.HeaderContextMenu.ShowAt(dataGrid, e.GetPosition(dataGrid));
161162
}
162163
// If user clicks on actual row
163164
else
164165
{
166+
var ObjectPressed = ((ObservableCollection<ListedItem>)dataGrid.ItemsSource)[RowPressed.GetIndex()];
167+
dataGrid.SelectedItems.Add(ObjectPressed);
165168
GenericFileBrowser.context.ShowAt(dataGrid, e.GetPosition(dataGrid));
166169
}
170+
171+
}
167172

173+
public static T FindParent<T>(DependencyObject child) where T : DependencyObject
174+
{
175+
T parent = null;
176+
DependencyObject CurrentParent = VisualTreeHelper.GetParent(child);
177+
while(CurrentParent != null)
178+
{
179+
if(CurrentParent is T)
180+
{
181+
parent = (T)CurrentParent;
182+
break;
183+
}
184+
CurrentParent = VisualTreeHelper.GetParent(CurrentParent);
185+
186+
}
187+
return parent;
168188
}
169189

170190
public static void FileList_RightTapped(object sender, RightTappedRoutedEventArgs e)

0 commit comments

Comments
 (0)