Skip to content

Commit

Permalink
Add separator between code samples, update code copy button to be on …
Browse files Browse the repository at this point in the history
…title line (microsoft#854)
  • Loading branch information
marcelwgn committed Jan 31, 2022
1 parent ec2f5ad commit dfa35dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
13 changes: 12 additions & 1 deletion XamlControlsGallery/Controls/ControlExample.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
</VisualState.Setters>
</VisualState>
</VisualStateGroup>

<VisualStateGroup x:Name="SampleCodeSeparatorStates">
<VisualState x:Name="SeparatorCollapsed"/>
<VisualState x:Name="SeparatorVisible">
<VisualState.Setters>
<Setter Target="SampleCodeSeparator.Visibility" Value="Visible"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Grid.RowDefinitions>
Expand Down Expand Up @@ -154,12 +163,14 @@
<TextBlock Text="Source code"/>
</muxc:Expander.Header>

<StackPanel x:DefaultBindMode="OneWay" Spacing="4">
<StackPanel x:DefaultBindMode="OneWay">
<controls:SampleCodePresenter
x:Name="XamlPresenter"
Code="{x:Bind Xaml}"
CodeSourceFile="{x:Bind XamlSource}"
Substitutions="{x:Bind Substitutions}"/>
<Border x:Name="SampleCodeSeparator" Visibility="Collapsed" Margin="0,20"
BorderThickness="1" BorderBrush="{ThemeResource SystemControlBackgroundBaseMediumBrush}"/>
<controls:SampleCodePresenter
x:Name="CSharpPresenter"
Code="{x:Bind CSharp}"
Expand Down
11 changes: 9 additions & 2 deletions XamlControlsGallery/Controls/ControlExample.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,21 @@ public int MinimumUniversalAPIContract
set { SetValue(MinimumUniversalAPIContractProperty, value); }
}

private ILanguage CSharpLanguage = Languages.CSharp;

public ControlExample()
{
this.InitializeComponent();
Substitutions = new List<ControlExampleSubstitution>();

ControlPresenter.RegisterPropertyChangedCallback(ContentPresenter.PaddingProperty, ControlPaddingChangedCallback);
this.Loaded += ControlExample_Loaded;
}

private void ControlExample_Loaded(object sender, RoutedEventArgs e)
{
if(!XamlPresenter.IsEmpty && !CSharpPresenter.IsEmpty)
{
VisualStateManager.GoToState(this, "SeparatorVisible", false);
}
}

private void rootGrid_Loaded(object sender, RoutedEventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions XamlControlsGallery/Controls/SampleCodePresenter.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
</VisualStateManager.VisualStateGroups>
<TextBlock x:Name="SampleHeader"/>
<ScrollViewer
x:Name="CodeScrollViewer" Padding="0,4,32,10"
x:Name="CodeScrollViewer" Padding="0,4,0,10"
HorizontalScrollBarVisibility="Auto" Grid.Row="1"
HorizontalScrollMode="Auto"
VerticalScrollBarVisibility="Disabled"
VerticalScrollMode="Disabled">
<ContentPresenter x:Name="CodePresenter" Loaded="CodePresenter_Loaded"/>
</ScrollViewer>
<Button x:Name="CopyCodeButton" Grid.Row="1"
<Button x:Name="CopyCodeButton" Grid.Row="0"
AutomationProperties.Name="Copy sample code"
ToolTipService.ToolTip="Copy sample code" VerticalAlignment="Top"
HorizontalAlignment="Right" Click="CopyCodeButton_Click" Padding="4">
Expand Down
2 changes: 2 additions & 0 deletions XamlControlsGallery/Controls/SampleCodePresenter.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public IList<ControlExampleSubstitution> Substitutions
set { SetValue(SubstitutionsProperty, value); }
}

public bool IsEmpty => Code.Length == 0 && CodeSourceFile == null;

private string actualCode = "";
private static Regex SubstitutionPattern = new Regex(@"\$\(([^\)]+)\)");

Expand Down

0 comments on commit dfa35dc

Please sign in to comment.