private async void NavigationFrame_Navigating(object sender, NavigatingCancelEventArgs navigationEventArgs) { ProcessSampleEditorTime(); SampleCategory category; if (navigationEventArgs.Parameter == null) { DataContext = null; HamburgerMenu.CurrentSample = null; category = navigationEventArgs.Parameter as SampleCategory; 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 sampleName = navigationEventArgs.Parameter.ToString(); HamburgerMenu.CurrentSample = await Samples.GetSampleByName(sampleName); DataContext = HamburgerMenu.CurrentSample; if (HamburgerMenu.CurrentSample == null) { HideInfoArea(); return; } category = await Samples.GetCategoryBySample(HamburgerMenu.CurrentSample); await Samples.PushRecentSample(HamburgerMenu.CurrentSample); var propertyDesc = HamburgerMenu.CurrentSample.PropertyDescriptor; InfoAreaPivot.Items.Clear(); if (propertyDesc != null) { _xamlRenderer.DataContext = propertyDesc.Expando; } Title.Text = HamburgerMenu.CurrentSample.Name; if (propertyDesc != null && propertyDesc.Options.Count > 0) { InfoAreaPivot.Items.Add(PropertiesPivotItem); } if (HamburgerMenu.CurrentSample.HasXAMLCode) { if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || HamburgerMenu.CurrentSample.DisableXamlEditorRendering) { // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise. XamlReadOnlyCodeRenderer.SetCode(HamburgerMenu.CurrentSample.UpdatedXamlCode, "xaml"); InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem); } else { XamlCodeRenderer.Text = HamburgerMenu.CurrentSample.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlPivotItem); _xamlCodeRendererSupported = true; } InfoAreaPivot.SelectedIndex = 0; } if (HamburgerMenu.CurrentSample.HasCSharpCode) { var code = await HamburgerMenu.CurrentSample.GetCSharpSourceAsync(); CSharpCodeRenderer.SetCode(code, "c#"); InfoAreaPivot.Items.Add(CSharpPivotItem); } if (HamburgerMenu.CurrentSample.HasJavaScriptCode) { var code = await HamburgerMenu.CurrentSample.GetJavaScriptSourceAsync(); JavaScriptCodeRenderer.SetCode(code, "js"); InfoAreaPivot.Items.Add(JavaScriptPivotItem); } if (!string.IsNullOrEmpty(HamburgerMenu.CurrentSample.CodeUrl)) { GitHub.NavigateUri = new Uri(HamburgerMenu.CurrentSample.CodeUrl); GitHub.Visibility = Visibility.Visible; } else { GitHub.Visibility = Visibility.Collapsed; } if (HamburgerMenu.CurrentSample.HasDocumentation) { var docs = await this.HamburgerMenu.CurrentSample.GetDocumentationAsync(); documentationPath = docs.path; if (!string.IsNullOrWhiteSpace(docs.contents)) { DocumentationTextblock.Text = docs.contents; InfoAreaPivot.Items.Add(DocumentationPivotItem); } } if (InfoAreaPivot.Items.Count == 0) { HideInfoArea(); } HamburgerMenu.Title = $"{category.Name} > {HamburgerMenu.CurrentSample?.Name}"; ApplicationViewExtensions.SetTitle(this, $"{category.Name} > {HamburgerMenu.CurrentSample?.Name}"); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.Parameter is Sample sample) { CurrentSample = sample; } if (CurrentSample != null) { if (!string.IsNullOrWhiteSpace(CurrentSample.Type)) { try { var pageInstance = Activator.CreateInstance(CurrentSample.PageType); SampleContent.Content = pageInstance; // Some samples use the OnNavigatedTo and OnNavigatedFrom // Can't use Frame here because some samples depend on the current Frame MethodInfo method = CurrentSample.PageType.GetMethod( "OnNavigatedTo", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { method.Invoke(pageInstance, new object[] { e }); } } catch { ExceptionNotification.Show("Sample Page failed to load."); } if (SamplePage != null) { SamplePage.Loaded += SamplePage_Loaded; } } else { _onlyDocumentation = true; } InfoAreaPivot.Items.Clear(); if (CurrentSample.HasXAMLCode) { // Load Sample Properties before we load sample (if we haven't before) await CurrentSample.PreparePropertyDescriptorAsync(); // We only have properties on examples with live XAML var propertyDesc = CurrentSample.PropertyDescriptor; if (propertyDesc != null) { _xamlRenderer.DataContext = propertyDesc.Expando; } if (propertyDesc?.Options.Count > 0) { InfoAreaPivot.Items.Add(PropertiesPivotItem); } if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop || CurrentSample.DisableXamlEditorRendering) { // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise. XamlReadOnlyCodeRenderer.SetCode(CurrentSample.UpdatedXamlCode, "xaml"); InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem); } else { XamlCodeEditor.Text = CurrentSample.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlPivotItem); _xamlCodeRendererSupported = true; } InfoAreaPivot.SelectedIndex = 0; } if (CurrentSample.HasCSharpCode) { var code = await CurrentSample.GetCSharpSourceAsync(); CSharpCodeRenderer.SetCode(code, "c#"); InfoAreaPivot.Items.Add(CSharpPivotItem); } if (CurrentSample.HasJavaScriptCode) { var code = await CurrentSample.GetJavaScriptSourceAsync(); JavaScriptCodeRenderer.SetCode(code, "js"); InfoAreaPivot.Items.Add(JavaScriptPivotItem); } if (CurrentSample.HasDocumentation) { #pragma warning disable SA1008 // Opening parenthesis must be spaced correctly var(contents, path) = await CurrentSample.GetDocumentationAsync(); #pragma warning restore SA1008 // Opening parenthesis must be spaced correctly documentationPath = path; if (!string.IsNullOrWhiteSpace(contents)) { DocumentationTextBlock.Text = contents; InfoAreaPivot.Items.Add(DocumentationPivotItem); } } // Hide the GitHub button if there isn't a CodeUrl. if (string.IsNullOrEmpty(CurrentSample.CodeUrl)) { GithubButton.Visibility = Visibility.Collapsed; } else { GithubButton.Visibility = Visibility.Visible; } DataContext = CurrentSample; if (InfoAreaPivot.Items.Count == 0) { SidePaneState = PaneState.None; } else { SidePaneState = _onlyDocumentation ? PaneState.Full : PaneState.Normal; } Shell.Current.SetAppTitle($"{CurrentSample.CategoryName} > {CurrentSample.Name}"); } else { ExceptionNotification.Show("Sample does not exist"); } if (!CanChangePaneState) { SampleTitleBar.Children.Remove(NarrowInfoButton); } if (e.NavigationMode != NavigationMode.Back) { var nop = Samples.PushRecentSample(CurrentSample); } }
private async void NavigationFrame_Navigating(object sender, NavigatingCancelEventArgs navigationEventArgs) { if (navigationEventArgs.SourcePageType == typeof(SamplePicker) || navigationEventArgs.Parameter == null) { DataContext = null; if (navigationEventArgs.Parameter != null) { var category = navigationEventArgs.Parameter as SampleCategory; if (category != null) { TrackingManager.TrackPage($"{navigationEventArgs.SourcePageType.Name} - {category.Name}"); } } HideInfoArea(); } else { TrackingManager.TrackPage(navigationEventArgs.SourcePageType.Name); ShowInfoArea(); var sampleName = navigationEventArgs.Parameter.ToString(); var sample = await Samples.GetSampleByName(sampleName); if (sample == null) { HideInfoArea(); return; } var propertyDesc = sample.PropertyDescriptor; DataContext = sample; InfoAreaPivot.Items.Clear(); if (propertyDesc != null) { NavigationFrame.DataContext = propertyDesc.Expando; } Title.Text = sample.Name; _currentSample = sample; if (propertyDesc != null && propertyDesc.Options.Count > 0) { InfoAreaPivot.Items.Add(PropertiesPivotItem); } if (sample.HasXAMLCode) { XamlCodeRenderer.XamlSource = _currentSample.UpdatedXamlCode; InfoAreaPivot.Items.Add(XamlPivotItem); InfoAreaPivot.SelectedIndex = 0; } if (sample.HasCSharpCode) { CSharpCodeRenderer.CSharpSource = await _currentSample.GetCSharpSourceAsync(); InfoAreaPivot.Items.Add(CSharpPivotItem); } if (sample.HasJavaScriptCode) { JavaScriptCodeRenderer.CSharpSource = await _currentSample.GetJavaScriptSourceAsync(); InfoAreaPivot.Items.Add(JavaScriptPivotItem); } UpdateRootGridMinWidth(); if (!string.IsNullOrEmpty(sample.CodeUrl)) { GitHub.NavigateUri = new Uri(sample.CodeUrl); GitHub.Visibility = Visibility.Visible; } else { GitHub.Visibility = Visibility.Collapsed; } if (sample.HasDocumentation) { InfoAreaPivot.Items.Add(DocumentationPivotItem); DocumentationTextblock.Text = await _currentSample.GetDocumentationAsync(); } if (InfoAreaPivot.Items.Count == 0) { HideInfoArea(); } } }
private async void UpdateSearchSuggestions() { _searchBox.ItemsSource = (await Samples.FindSamplesByName(_searchBox.Text)).OrderBy(s => s.Name); }
private async void ShowSamplePicker(Sample[] samples = null, bool group = false) { // UNO TODO // force materialization FindName("SamplePickerGrid"); if (samples == null && _currentSample != null) { var category = await Samples.GetCategoryBySample(_currentSample); if (category != null) { samples = category.Samples; } } if (samples == null) { samples = (await Samples.GetCategoriesAsync()).FirstOrDefault()?.Samples; } if (samples == null) { return; } if (SamplePickerGrid.Visibility == Windows.UI.Xaml.Visibility.Visible && SamplePickerGridView.ItemsSource is Sample[] currentSamples && currentSamples.Count() == samples.Count() && currentSamples.Except(samples).Count() == 0) { return; } SamplePickerGridView.ItemsSource = samples; var groups = samples.GroupBy(sample => sample.Subcategory); if (group && groups.Count() > 1) { SampleView.IsSourceGrouped = true; SampleView.Source = groups.OrderBy(g => g.Key); } else { SampleView.IsSourceGrouped = false; SampleView.Source = samples; } SamplePickerGridView.ItemsSource = SampleView.View; if (_currentSample != null && samples.Contains(_currentSample)) { SamplePickerGridView.SelectedItem = _currentSample; } else { SamplePickerGridView.SelectedItem = null; } SamplePickerGrid.Visibility = Windows.UI.Xaml.Visibility.Visible; }