Skip to content

Commit 7e7902f

Browse files
committed
Ensure Extended Item Properties Are Loaded Upon Initial Navigation
1 parent 80519d0 commit 7e7902f

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

Files/Filesystem/ItemViewModel.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,22 @@ public static extern IntPtr FindFirstFileExFromApp(
526526

527527
[DllImport("api-ms-win-core-file-l1-1-0.dll")]
528528
static extern bool FindClose(IntPtr hFindFile);
529-
530-
bool isLoadingItems = false;
529+
private bool _isLoadingItems = false;
530+
public bool isLoadingItems
531+
{
532+
get
533+
{
534+
return _isLoadingItems;
535+
}
536+
internal set
537+
{
538+
if(_isLoadingItems != value)
539+
{
540+
_isLoadingItems = value;
541+
NotifyPropertyChanged("isLoadingItems");
542+
}
543+
}
544+
}
531545

532546
class PartialStorageItem
533547
{
@@ -564,7 +578,7 @@ public async void LoadExtendedItemProperties(ListedItem item)
564578
}
565579
catch (UnauthorizedAccessException)
566580
{
567-
await App.consentDialog.ShowAsync();
581+
item.ItemPropertiesInitialized = true;
568582
return;
569583
}
570584
catch (FileNotFoundException)
@@ -587,7 +601,7 @@ public async void LoadExtendedItemProperties(ListedItem item)
587601
}
588602
catch (UnauthorizedAccessException)
589603
{
590-
await App.consentDialog.ShowAsync();
604+
item.ItemPropertiesInitialized = true;
591605
return;
592606
}
593607
catch (FileNotFoundException)

Files/Interacts/Interaction.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,22 @@ public void AllView_RightTapped(object sender, RightTappedRoutedEventArgs e)
241241

242242
}
243243

244+
public static T FindChild<T>(DependencyObject startNode) where T : DependencyObject
245+
{
246+
int count = VisualTreeHelper.GetChildrenCount(startNode);
247+
for (int i = 0; i < count; i++)
248+
{
249+
DependencyObject current = VisualTreeHelper.GetChild(startNode, i);
250+
if ((current.GetType()).Equals(typeof(T)) || (current.GetType().GetTypeInfo().IsSubclassOf(typeof(T))))
251+
{
252+
T asType = (T)current;
253+
return asType;
254+
}
255+
FindChild<T>(current);
256+
}
257+
return null;
258+
}
259+
244260
public static void FindChildren<T>(List<T> results, DependencyObject startNode) where T : DependencyObject
245261
{
246262
int count = VisualTreeHelper.GetChildrenCount(startNode);

Files/UserControls/GenericFileBrowser.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
x:Name="AllView"
296296
Grid.Row="3"
297297
Margin="12,12,0,0"
298-
HorizontalAlignment="Stretch"
298+
HorizontalAlignment="Left"
299299
x:FieldModifier="public"
300300
AllowDrop="True"
301301
AutoGenerateColumns="False"

Files/UserControls/GenericFileBrowser.xaml.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
using System.Linq;
1818
using Microsoft.Toolkit.Uwp.UI.Behaviors;
1919
using Windows.Foundation;
20+
using Windows.UI.Xaml.Media;
21+
using System.Collections.Generic;
2022

2123
namespace Files
2224
{
@@ -78,7 +80,7 @@ public GenericFileBrowser()
7880
App.CurrentInstance.ViewModel.PropertyChanged += ViewModel_PropertyChanged;
7981
}
8082

81-
private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
83+
private async void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
8284
{
8385
if (e.PropertyName == "DirectorySortOption")
8486
{
@@ -103,6 +105,26 @@ private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e
103105
// Swap arrows
104106
SortedColumn = _sortedColumn;
105107
}
108+
else if (e.PropertyName == "isLoadingItems")
109+
{
110+
if (!AssociatedViewModel.isLoadingItems && AssociatedViewModel.FilesAndFolders.Count > 0)
111+
{
112+
var allRows = new List<DataGridRow>();
113+
114+
Interacts.Interaction.FindChildren<DataGridRow>(allRows, AllView);
115+
foreach(DataGridRow row in allRows.Take(20))
116+
{
117+
if (!(row.DataContext as ListedItem).ItemPropertiesInitialized)
118+
{
119+
await Window.Current.CoreWindow.Dispatcher.RunIdleAsync((e) =>
120+
{
121+
App.CurrentInstance.ViewModel.LoadExtendedItemProperties(row.DataContext as ListedItem);
122+
(row.DataContext as ListedItem).ItemPropertiesInitialized = true;
123+
});
124+
}
125+
}
126+
}
127+
}
106128
}
107129

108130
private void AllView_DragOver(object sender, DragEventArgs e)

0 commit comments

Comments
 (0)