protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); NavigationFrame.Navigating += NavigationFrame_Navigating; NavigationFrame.Navigated += NavigationFrameOnNavigated; SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; // Get list of patterns var patternCategories = (await Patterns.GetCategoriesAsync()).ToList(); HamburgerMenu.ItemsSource = patternCategories; // Options HamburgerMenu.OptionsItemsSource = new[] { new Option { Glyph = "\xE10F", Name = "About", PageType = typeof(About) } }; HideInfoArea(); NavigationFrame.Navigate(typeof(About)); if (!string.IsNullOrWhiteSpace(e?.Parameter?.ToString())) { var parser = DeepLinkParser.Create(e.Parameter.ToString()); var targetPattern = await Pattern.FindAsync(parser.Root, parser["pattern"]); if (targetPattern != null) { NavigateToPattern(targetPattern); } } }
internal static async Task <Pattern> FindAsync(string category, string name) { var categories = await Patterns.GetCategoriesAsync(); return(categories? .FirstOrDefault(c => c.Name.Equals(category, StringComparison.OrdinalIgnoreCase))? .Patterns .FirstOrDefault(s => s.Name.Equals(name, StringComparison.OrdinalIgnoreCase))); }
public async Task NavigateToPattern(string patternType, object parameter = null) { var targetPattern = await Patterns.GetPatternByName(patternType); if (targetPattern != null) { NavigateToPattern(targetPattern, parameter); } }
/// <summary> /// Navigates to a Pattern via a deep link. /// </summary> /// <param name="deepLink">The deep link. Specified as protocol://[collectionName]?pattern=[patternName]</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task NavigateToPatternAsync(string deepLink) { var parser = DeepLinkParser.Create(deepLink); var targetPattern = await Patterns.GetPatternByName(parser["pattern"]); if (targetPattern != null) { NavigateToPattern(targetPattern); } }
private async void NavigationFrame_Navigating(object sender, NavigatingCancelEventArgs navigationEventArgs) { ProcessPatternEditorTime(); MenuCategory category; if (navigationEventArgs.Parameter == null) { DataContext = null; HamburgerMenu.CurrentPattern = null; category = navigationEventArgs.Parameter as MenuCategory; if (category != null) { TrackingManager.TrackPage($"{navigationEventArgs.SourcePageType.Name} - {category.Name}"); } else { TrackingManager.TrackPage($"{navigationEventArgs.SourcePageType.Name}"); } HideInfoArea(); } else { TrackingManager.TrackPage(navigationEventArgs.SourcePageType.Name); Commands.Clear(); ShowInfoArea(); var patternName = navigationEventArgs.Parameter.ToString(); HamburgerMenu.CurrentPattern = await Patterns.GetPatternByName(patternName); DataContext = HamburgerMenu.CurrentPattern; if (HamburgerMenu.CurrentPattern == null) { HideInfoArea(); return; } category = await Patterns.GetCategoryByPattern(HamburgerMenu.CurrentPattern); await Patterns.PushRecentPattern(HamburgerMenu.CurrentPattern); var propertyDesc = HamburgerMenu.CurrentPattern.PropertyDescriptor; InfoAreaPivot.Items.Clear(); if (propertyDesc != null) { _xamlRenderer.DataContext = propertyDesc.Expando; } Title.Text = HamburgerMenu.CurrentPattern.Name; if (propertyDesc != null && propertyDesc.Options.Count > 0) { InfoAreaPivot.Items.Add(PropertiesPivotItem); } if (HamburgerMenu.CurrentPattern.HasXAMLCode) { if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || HamburgerMenu.CurrentPattern.DisableXamlEditorRendering) { // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise. XamlReadOnlyCodeRenderer.XamlSource = HamburgerMenu.CurrentPattern.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem); } else { XamlCodeRenderer.Text = HamburgerMenu.CurrentPattern.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlPivotItem); _xamlCodeRendererSupported = true; } InfoAreaPivot.SelectedIndex = 0; } if (HamburgerMenu.CurrentPattern.HasCSharpCode) { CSharpCodeRenderer.CSharpSource = await this.HamburgerMenu.CurrentPattern.GetCSharpSourceAsync(); InfoAreaPivot.Items.Add(CSharpPivotItem); } if (HamburgerMenu.CurrentPattern.HasJavaScriptCode) { JavaScriptCodeRenderer.CSharpSource = await this.HamburgerMenu.CurrentPattern.GetJavaScriptSourceAsync(); InfoAreaPivot.Items.Add(JavaScriptPivotItem); } if (!string.IsNullOrEmpty(HamburgerMenu.CurrentPattern.CodeUrl)) { GitHub.NavigateUri = new Uri(HamburgerMenu.CurrentPattern.CodeUrl); GitHub.Visibility = Visibility.Visible; } else { GitHub.Visibility = Visibility.Collapsed; } if (HamburgerMenu.CurrentPattern.HasDocumentation) { var docs = await this.HamburgerMenu.CurrentPattern.GetDocumentationAsync(); if (!string.IsNullOrWhiteSpace(docs)) { DocumentationTextblock.Text = docs; InfoAreaPivot.Items.Add(DocumentationPivotItem); } } if (InfoAreaPivot.Items.Count == 0) { HideInfoArea(); } HamburgerMenu.Title = $"{category.Name} > {HamburgerMenu.CurrentPattern?.Name}"; ApplicationView.SetTitle(this, $"{category.Name} > {HamburgerMenu.CurrentPattern?.Name}"); } }