diff --git a/WinUIGallery/Controls/ControlExample.xaml b/WinUIGallery/Controls/ControlExample.xaml index 81cfa822b..9749ad8cc 100644 --- a/WinUIGallery/Controls/ControlExample.xaml +++ b/WinUIGallery/Controls/ControlExample.xaml @@ -8,12 +8,34 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:muxc="using:Microsoft.UI.Xaml.Controls" + xmlns:animations="using:CommunityToolkit.WinUI.Animations" x:Name="RootPanel" Margin="0,16,0,0" d:DesignHeight="250" d:DesignWidth="1000" mc:Ignorable="d"> - + + + + + + + + + + @@ -138,26 +160,38 @@ + + + + + + + + + - - - - - + + + + + + - - - - - - - - - diff --git a/WinUIGallery/Controls/ControlExample.xaml.cs b/WinUIGallery/Controls/ControlExample.xaml.cs index 99c3b425d..924958a15 100644 --- a/WinUIGallery/Controls/ControlExample.xaml.cs +++ b/WinUIGallery/Controls/ControlExample.xaml.cs @@ -7,16 +7,12 @@ // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // //********************************************************* -using WinUIGallery.Common; using WinUIGallery.Helper; -using ColorCode; -using ColorCode.Common; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; -using System.Text.RegularExpressions; using System.Threading.Tasks; using Windows.ApplicationModel.Core; using Windows.Foundation; @@ -30,7 +26,6 @@ using Microsoft.UI.Xaml.Markup; using Microsoft.UI.Xaml.Media; using Microsoft.UI.Xaml.Media.Imaging; -using System.Reflection; namespace WinUIGallery { @@ -125,28 +120,28 @@ public object Options set { SetValue(OptionsProperty, value); } } - public static readonly DependencyProperty XamlProperty = DependencyProperty.Register("Xaml", typeof(string), typeof(ControlExample), new PropertyMetadata(null)); + public static readonly DependencyProperty XamlProperty = DependencyProperty.Register("Xaml", typeof(string), typeof(ControlExample), new PropertyMetadata(null, OnXamlChanged)); public string Xaml { get { return (string)GetValue(XamlProperty); } set { SetValue(XamlProperty, value); } } - public static readonly DependencyProperty XamlSourceProperty = DependencyProperty.Register("XamlSource", typeof(object), typeof(ControlExample), new PropertyMetadata(null)); + public static readonly DependencyProperty XamlSourceProperty = DependencyProperty.Register("XamlSource", typeof(object), typeof(ControlExample), new PropertyMetadata(null, OnXamlChanged)); public string XamlSource { get { return (string)GetValue(XamlSourceProperty); } set { SetValue(XamlSourceProperty, value); } } - public static readonly DependencyProperty CSharpProperty = DependencyProperty.Register("CSharp", typeof(string), typeof(ControlExample), new PropertyMetadata(null)); + public static readonly DependencyProperty CSharpProperty = DependencyProperty.Register("CSharp", typeof(string), typeof(ControlExample), new PropertyMetadata(null, OnCSharpChanged)); public string CSharp { get { return (string)GetValue(CSharpProperty); } set { SetValue(CSharpProperty, value); } } - public static readonly DependencyProperty CSharpSourceProperty = DependencyProperty.Register("CSharpSource", typeof(object), typeof(ControlExample), new PropertyMetadata(null)); + public static readonly DependencyProperty CSharpSourceProperty = DependencyProperty.Register("CSharpSource", typeof(object), typeof(ControlExample), new PropertyMetadata(null, OnCSharpChanged)); public string CSharpSource { get { return (string)GetValue(CSharpSourceProperty); } @@ -209,12 +204,7 @@ public ControlExample() private void ControlExample_Loaded(object sender, RoutedEventArgs e) { - if(!XamlPresenter.IsEmpty && !CSharpPresenter.IsEmpty) - { - VisualStateManager.GoToState(this, "SeparatorVisible", false); - } HeaderTextPresenter.Visibility = string.IsNullOrEmpty(HeaderText) ? Visibility.Collapsed : Visibility.Visible; - } private void rootGrid_Loaded(object sender, RoutedEventArgs e) @@ -432,5 +422,68 @@ private void EvaluatePadding() break; } } + private void SelectorBarItem_Loaded(object sender, RoutedEventArgs e) + { + var item = sender as SelectorBarItem; + if (item == null) + return; + + if (item.Tag.ToString().Equals("Xaml", StringComparison.OrdinalIgnoreCase)) + { + item.Visibility = string.IsNullOrEmpty(Xaml) && string.IsNullOrEmpty(XamlSource) ? Visibility.Collapsed : Visibility.Visible; + } + else if (item.Tag.ToString().Equals("CSharp", StringComparison.OrdinalIgnoreCase)) + { + item.Visibility = string.IsNullOrEmpty(CSharp) && string.IsNullOrEmpty(CSharpSource) ? Visibility.Collapsed : Visibility.Visible; + } + + var firstVisibileItem = SelectorBarControl.Items.Where(x => x.Visibility == Visibility.Visible).FirstOrDefault(); + if (firstVisibileItem != null) + { + firstVisibileItem.IsSelected = true; + } + + HandlePresenterVisibility(); + } + + private static void OnXamlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctrl = (ControlExample)d; + if (ctrl != null) + { + ctrl.SelectorBarItem_Loaded(ctrl.SelectorBarXamlItem, null); + } + } + private static void OnCSharpChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctrl = (ControlExample)d; + if (ctrl != null) + { + ctrl.SelectorBarItem_Loaded(ctrl.SelectorBarCSharpItem, null); + } + } + + private void SelectorBarControl_SelectionChanged(SelectorBar sender, SelectorBarSelectionChangedEventArgs args) + { + HandlePresenterVisibility(); + } + + private void HandlePresenterVisibility() + { + var selectedItem = SelectorBarControl.SelectedItem; + if (selectedItem != null) + { + if (selectedItem.Tag.ToString().Equals("Xaml", StringComparison.OrdinalIgnoreCase)) + { + XamlPresenter.Visibility = Visibility.Visible; + CSharpPresenter.Visibility = Visibility.Collapsed; + } + else if (selectedItem.Tag.ToString().Equals("CSharp", StringComparison.OrdinalIgnoreCase)) + { + CSharpPresenter.Visibility = Visibility.Visible; + XamlPresenter.Visibility = Visibility.Collapsed; + } + } + } } } diff --git a/WinUIGallery/Controls/SampleCodePresenter.xaml b/WinUIGallery/Controls/SampleCodePresenter.xaml index 37b7a0db4..2f7cd7f1f 100644 --- a/WinUIGallery/Controls/SampleCodePresenter.xaml +++ b/WinUIGallery/Controls/SampleCodePresenter.xaml @@ -15,24 +15,18 @@ BorderBrush="{Binding BorderBrush, Mode=OneWay}" BorderThickness="{Binding BorderThickness, Mode=OneWay}" CornerRadius="{Binding CornerRadius, Mode=OneWay}"> - - - - - + VerticalScrollBarVisibility="Auto" + VerticalScrollMode="Auto"> - - - - - - - - - - + + - - - diff --git a/WinUIGallery/Controls/SampleCodePresenter.xaml.cs b/WinUIGallery/Controls/SampleCodePresenter.xaml.cs index ba63c39a9..fe3714922 100644 --- a/WinUIGallery/Controls/SampleCodePresenter.xaml.cs +++ b/WinUIGallery/Controls/SampleCodePresenter.xaml.cs @@ -11,25 +11,20 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; -using System.Threading.Tasks; using WinUIGallery.Helper; using ColorCode; using ColorCode.Common; using Windows.ApplicationModel.DataTransfer; using Windows.Storage; -using Windows.System; -using Windows.UI.Core; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Media; -using WinUIGallery.Common; using System.Reflection; using System.IO; using Microsoft.UI.Xaml.Automation; namespace WinUIGallery.Controls { - public enum SampleCodePresenterType { XAML, @@ -176,7 +171,6 @@ private async void FormatAndRenderSampleFromFile(string sourceRelativePath, Cont { if (sourceRelativePath != null && sourceRelativePath.EndsWith("txt")) { - string sampleString = null; StorageFile file = null; if (!NativeHelper.IsAppPackaged) @@ -227,11 +221,10 @@ private void FormatAndRenderSampleFromString(string sampleString, ContentPresent actualCode = sampleString; - var name = GetSampleLanguageVisualState() == "InlineSample" ? actualCode : SampleHeader.Text; + var name = GetSampleLanguageVisualState() == "InlineSample" ? actualCode : SampleType.ToString(); var automationName = "Copy " + name + " Code"; AutomationProperties.SetName(CopyCodeButton, automationName); - var formatter = GenerateRichTextFormatter(); if (SampleType == SampleCodePresenterType.Inline) {