Skip to content

Commit a141182

Browse files
authored
Fixed an exception while writing some paths on the address bar (#6077)
1 parent 6a91f76 commit a141182

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Files/Filesystem/StorageFileHelpers/StorageFileExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ public async static Task<IList<StorageFileWithPath>> GetFilesWithPathAsync(this
217217

218218
public async static Task<IList<StorageFolderWithPath>> GetFoldersWithPathAsync(this StorageFolderWithPath parentFolder, string nameFilter, uint maxNumberOfItems = uint.MaxValue)
219219
{
220+
if (parentFolder == null)
221+
{
222+
return null;
223+
}
224+
220225
var queryOptions = new QueryOptions();
221226
queryOptions.ApplicationSearchFilter = $"System.FileName:{nameFilter}*";
222227
BaseStorageFolderQueryResult queryResult = parentFolder.Folder.CreateFolderQueryWithOptions(queryOptions);

Files/ViewModels/NavToolbarViewModel.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,11 @@ public bool IsSearchBoxVisible
275275
public string PathText
276276
{
277277
get => pathText;
278-
set => SetProperty(ref pathText, value);
278+
set
279+
{
280+
pathText = value;
281+
OnPropertyChanged(nameof(PathText));
282+
}
279283
}
280284

281285
public ObservableCollection<ListedItem> NavigationBarSuggestions = new ObservableCollection<ListedItem>();
@@ -488,9 +492,11 @@ public bool IsEditModeEnabled
488492
{
489493
EditModeEnabled?.Invoke(this, new EventArgs());
490494

491-
var visiblePath = NavToolbar.FindDescendant("VisiblePath") as Control;
495+
var visiblePath = NavToolbar.FindDescendant<AutoSuggestBox>(x => x.Name == "VisiblePath");
492496
visiblePath?.Focus(FocusState.Programmatic);
493497
visiblePath?.FindDescendant<TextBox>()?.SelectAll();
498+
499+
AddressBarTextEntered?.Invoke(this, new AddressBarTextEnteredEventArgs() { AddressBarTextField = visiblePath });
494500
}
495501
else
496502
{

Files/ViewModels/Previews/BasePreviewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static async Task<string> ReadFileAsText(BaseStorageFile file, int maxLen
150150
{
151151
var buffer = new byte[maxLength];
152152
bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
153-
result.Append(Encoding.UTF8.GetString(buffer));
153+
result.Append(Encoding.UTF8.GetString(buffer, 0, bytesRead));
154154
} while (bytesRead > 0 && result.Length <= maxLength);
155155
return result.ToString();
156156
}

0 commit comments

Comments
 (0)