Exemplo n.º 1
0
        public void SetSelectedPathOrNavigate(string navigationPath, Type sourcePageType, NavigationArguments navArgs = null)
        {
            var destPath        = navArgs != null ? (navArgs.IsSearchResultPage ? navArgs.SearchPathParam : navArgs.NavPathParam) : navigationPath;
            var columnPath      = ((ColumnHost.ActiveBlades.Last().Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;
            var columnFirstPath = ((ColumnHost.ActiveBlades.First().Content as Frame)?.Content as ColumnShellPage)?.FilesystemViewModel.WorkingDirectory;

            if (string.IsNullOrEmpty(destPath) || string.IsNullOrEmpty(destPath) || string.IsNullOrEmpty(destPath))
            {
                ParentShellPageInstance.NavigateToPath(navigationPath, sourcePageType, navArgs);
                return;
            }

            var destComponents        = StorageFileExtensions.GetDirectoryPathComponents(destPath);
            var columnComponents      = StorageFileExtensions.GetDirectoryPathComponents(columnPath);
            var columnFirstComponents = StorageFileExtensions.GetDirectoryPathComponents(columnFirstPath);

            var lastCommonItemIndex = columnComponents
                                      .Select((value, index) => new { value, index })
                                      .LastOrDefault(x => x.index < destComponents.Count && x.value.Path == destComponents[x.index].Path)?.index ?? -1;

            var relativeIndex = lastCommonItemIndex - (columnFirstComponents.Count - 1);

            if (relativeIndex < 0 || destComponents.Count - (lastCommonItemIndex + 1) > 1) // Going above parent or too deep down
            {
                ParentShellPageInstance.NavigateToPath(navigationPath, sourcePageType, navArgs);
            }
            else
            {
                DismissOtherBlades(relativeIndex);

                for (int ii = lastCommonItemIndex + 1; ii < destComponents.Count; ii++)
                {
                    var frame = new Frame();
                    frame.Navigated += Frame_Navigated;
                    var newblade = new BladeItem();
                    newblade.Content = frame;
                    ColumnHost.Items.Add(newblade);

                    if (navArgs != null)
                    {
                        frame.Navigate(typeof(ColumnShellPage), new ColumnParam
                        {
                            Column               = ColumnHost.ActiveBlades.IndexOf(newblade),
                            IsSearchResultPage   = navArgs.IsSearchResultPage,
                            SearchQuery          = navArgs.SearchQuery,
                            NavPathParam         = destComponents[ii].Path,
                            SearchUnindexedItems = navArgs.SearchUnindexedItems,
                            SearchPathParam      = navArgs.SearchPathParam
                        });
                    }
                    else
                    {
                        frame.Navigate(typeof(ColumnShellPage), new ColumnParam
                        {
                            Column       = ColumnHost.ActiveBlades.IndexOf(newblade),
                            NavPathParam = destComponents[ii].Path
                        });
                    }
                }
            }
        }