Ejemplo n.º 1
0
        private async void ShowSamplePicker(Sample[] samples = null, bool group = false)
        {
            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;
        }
        private async Task SetNavViewSelectionAsync()
        {
            if (_currentSample != null)
            {
                var category = await Samples.GetCategoryBySample(_currentSample);

                if ((NavView.MenuItemsSource as IEnumerable <SampleCategory>).Contains(category))
                {
                    NavView.SelectedItem = category;
                }
            }
            else
            {
                NavView.SelectedItem = null;
            }
        }
Ejemplo n.º 3
0
        private async void ShowSamplePicker(Sample[] samples = null)
        {
            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;

            if (_currentSample != null && samples.Contains(_currentSample))
            {
                SamplePickerGridView.SelectedItem = _currentSample;
            }
            else
            {
                SamplePickerGridView.SelectedItem = null;
            }

            SamplePickerGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
Ejemplo n.º 4
0
        private async Task SetHamburgerMenuSelection()
        {
            if (NavigationFrame.SourcePageType == typeof(SamplePicker))
            {
                // This is a search
                HamburgerMenu.SelectedItem        = null;
                HamburgerMenu.SelectedOptionsItem = null;
            }
            else if (_currentSample != null)
            {
                var category = await Samples.GetCategoryBySample(_currentSample);

                if (HamburgerMenu.Items.Contains(category))
                {
                    HamburgerMenu.SelectedItem        = category;
                    HamburgerMenu.SelectedOptionsItem = null;
                }
            }
            else
            {
                HamburgerMenu.SelectedItem         = null;
                HamburgerMenu.SelectedOptionsIndex = 0;
            }
        }
Ejemplo n.º 5
0
        private async void NavigationFrame_Navigating(object sender, NavigatingCancelEventArgs navigationEventArgs)
        {
            ProcessSampleEditorTime();

            SampleCategory category;

            if (navigationEventArgs.SourcePageType == typeof(SamplePicker) || navigationEventArgs.Parameter == null)
            {
                DataContext    = null;
                _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();
                _currentSample = await Samples.GetSampleByName(sampleName);

                DataContext = _currentSample;

                if (_currentSample == null)
                {
                    HideInfoArea();
                    return;
                }

                category = await Samples.GetCategoryBySample(_currentSample);

                await Samples.PushRecentSample(_currentSample);

                var propertyDesc = _currentSample.PropertyDescriptor;

                InfoAreaPivot.Items.Clear();

                if (propertyDesc != null)
                {
                    _xamlRenderer.DataContext = propertyDesc.Expando;
                }

                Title.Text = _currentSample.Name;

                if (propertyDesc != null && propertyDesc.Options.Count > 0)
                {
                    InfoAreaPivot.Items.Add(PropertiesPivotItem);
                }

                if (_currentSample.HasXAMLCode)
                {
                    if (AnalyticsInfo.VersionInfo.GetDeviceFormFactor() != DeviceFormFactor.Desktop)
                    {
                        // Only makes sense (and works) for now to show Live Xaml on Desktop, so fallback to old system here otherwise.
                        XamlReadOnlyCodeRenderer.XamlSource = _currentSample.UpdatedXamlCode;

                        InfoAreaPivot.Items.Add(XamlReadOnlyPivotItem);
                    }
                    else
                    {
                        XamlCodeRenderer.Text = _currentSample.UpdatedXamlCode;

                        InfoAreaPivot.Items.Add(XamlPivotItem);

                        _xamlCodeRendererSupported = true;
                    }

                    InfoAreaPivot.SelectedIndex = 0;
                }

                if (_currentSample.HasCSharpCode)
                {
                    CSharpCodeRenderer.CSharpSource = await this._currentSample.GetCSharpSourceAsync();

                    InfoAreaPivot.Items.Add(CSharpPivotItem);
                }

                if (_currentSample.HasJavaScriptCode)
                {
                    JavaScriptCodeRenderer.CSharpSource = await this._currentSample.GetJavaScriptSourceAsync();

                    InfoAreaPivot.Items.Add(JavaScriptPivotItem);
                }

                if (!string.IsNullOrEmpty(_currentSample.CodeUrl))
                {
                    GitHub.NavigateUri = new Uri(_currentSample.CodeUrl);
                    GitHub.Visibility  = Visibility.Visible;
                }
                else
                {
                    GitHub.Visibility = Visibility.Collapsed;
                }

                if (_currentSample.HasDocumentation)
                {
                    var docs = await this._currentSample.GetDocumentationAsync();

                    if (!string.IsNullOrWhiteSpace(docs))
                    {
                        DocumentationTextblock.Text = docs;
                        InfoAreaPivot.Items.Add(DocumentationPivotItem);
                    }
                }

                if (InfoAreaPivot.Items.Count == 0)
                {
                    HideInfoArea();
                }

                TitleTextBlock.Text = $"{category.Name} -> {_currentSample?.Name}";
                ApplicationView.SetTitle(this, $"{category.Name} - {_currentSample?.Name}");
            }

            await SetHamburgerMenuSelection();
        }
Ejemplo n.º 6
0
        private async void NavigationFrame_Navigating(object sender, NavigatingCancelEventArgs navigationEventArgs)
        {
            SampleCategory category;

            if (navigationEventArgs.SourcePageType == typeof(SamplePicker) || navigationEventArgs.Parameter == null)
            {
                DataContext = null;
                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;
                }

                category = await Samples.GetCategoryBySample(sample);

                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);
                }

                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();
                }
            }

            if (category == null && navigationEventArgs.SourcePageType == typeof(SamplePicker))
            {
                // This is a search
                HamburgerMenu.SelectedItem        = null;
                HamburgerMenu.SelectedOptionsItem = null;
            }
            else
            {
                if (HamburgerMenu.Items.Contains(category))
                {
                    HamburgerMenu.SelectedItem        = category;
                    HamburgerMenu.SelectedOptionsItem = null;
                }
                else
                {
                    HamburgerMenu.SelectedItem         = null;
                    HamburgerMenu.SelectedOptionsIndex = category != null ? 0 : 1;
                }
            }
        }