Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6f12714
Added improved default control and style examples to ProjectTemplate
Arlodotexe Jun 17, 2022
5dfd11c
Fixed code style issues
Arlodotexe Jun 17, 2022
8cfeb9d
Fixed xaml styling
Arlodotexe Jun 17, 2022
46a3c7a
Fixed compiler errors
Arlodotexe Jun 17, 2022
b72364e
Don't throw if template part is missing
Arlodotexe Jun 18, 2022
a31ec63
Fixed missing compilation conditional when template is generated
Arlodotexe Jun 20, 2022
8d522a5
Fixed missing compilation conditional when template is generated
Arlodotexe Jun 20, 2022
6d84ee2
Removed Rns from namespaces
Arlodotexe Jun 20, 2022
f46651f
Use is not null instead of returning
Arlodotexe Jun 20, 2022
7124bb4
Merge main
Arlodotexe Jun 22, 2022
5e10461
Fixed issue where using the same property name in multiple samples wi…
Arlodotexe Jun 24, 2022
a47f490
Added default templated control examples
Arlodotexe Jun 24, 2022
4c5859c
Merge main
Arlodotexe Jun 24, 2022
c4aac54
Fixed compiler error on Android
Arlodotexe Jun 24, 2022
37476b4
Removed unused usings
Arlodotexe Jun 24, 2022
c714c3f
Removed leftover test code
Arlodotexe Jun 24, 2022
f81d1e8
Added TestMethod attribute back
Arlodotexe Jun 24, 2022
8aeb435
Added event handling examples, extra comments
Arlodotexe Jun 24, 2022
3c43d68
Use protected property for storing template part, fixed event unsubsc…
Arlodotexe Jun 24, 2022
5a22427
Add missing period to code comment.
Arlodotexe Jun 24, 2022
516328e
Templated control examples for x:Bind and classic binding are now com…
Arlodotexe Jun 24, 2022
13d462f
Apply xaml styling missed by autoformat
Arlodotexe Jun 24, 2022
b0b8d59
Added missing file headers
Arlodotexe Jun 27, 2022
f163437
Fixed compiler errors
Arlodotexe Jun 27, 2022
3893b01
Fixed more compiler errors
Arlodotexe Jun 27, 2022
59e0036
Ran xaml styler
Arlodotexe Jun 27, 2022
f9eda93
WIP: implicit styles via Generic.xaml
Arlodotexe Jun 27, 2022
b4f5f26
Fixed applying default styles
Arlodotexe Jun 27, 2022
41e7bb4
Fixed namespaces
Arlodotexe Jun 28, 2022
f793003
Ran XAML styler
Arlodotexe Jun 28, 2022
0a2bf51
Ran XAML styler on specific failing files
Arlodotexe Jun 28, 2022
01fc1f0
Renamed DefaultTemplatedControlStyle to DefaultProjectTemplateStyle
Arlodotexe Jun 28, 2022
921f4a1
Removed ItemGroup content covered by wildcard
Arlodotexe Jun 28, 2022
1e7543e
Merge branch 'main' into feature/default-project-controls
Arlodotexe Jun 28, 2022
36568d4
Fixed invalid namespace
Arlodotexe Jun 28, 2022
6fe0ab3
Ran XAML styler on failing files
Arlodotexe Jun 28, 2022
ab4ad5c
Fixed compiler warning
Arlodotexe Jun 28, 2022
23085b2
Fixed unit test invoking on wrong thread
Arlodotexe Jun 28, 2022
910dd57
Removed uneeded x:Name
Arlodotexe Jun 28, 2022
56a898b
Replaced CustomTemplatedControlStyle with CustomProjectTemplateStyle
Arlodotexe Jun 28, 2022
5d382e4
Replaced TemplatedControlSample with ProjectTemplateControlSample
Arlodotexe Jun 28, 2022
6e1ca59
Removed unused test page
Arlodotexe Jun 28, 2022
23002bc
Renamed DefaultTemplatedControlItemPadding to DefaultProjectTemplateI…
Arlodotexe Jun 28, 2022
bec9d59
Made default style keys unique between variations
Arlodotexe Jun 28, 2022
377e0d7
Removed extra ItemGroups covered by wildcards
Arlodotexe Jun 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace CommunityToolkit.Labs.Core.SourceGenerators;
public class ToolkitSampleOptionGenerator : IIncrementalGenerator
{
private readonly HashSet<string> _handledPropertyNames = new();
private readonly HashSet<ToolkitSampleOptionBaseAttribute> _handledAttributes = new();
private readonly HashSet<ISymbol> _handledContainingClasses = new(SymbolEqualityComparer.Default);

public void Initialize(IncrementalGeneratorInitializationContext context)
Expand Down Expand Up @@ -60,13 +59,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
ctx.AddSource($"{data.ContainingClassSymbol}.GeneratedPropertyContainer.g", propertyContainerSource);
}

if (!_handledAttributes.Add(data.Attribute))
return;
var name = $"{data.ContainingClassSymbol}.Property.{data.Attribute.Name}.g";

var dependencyPropertySource = BuildProperty(data.ContainingClassSymbol, data.Attribute.Name, data.Attribute.TypeName, data.Type);

if (_handledPropertyNames.Add(data.Attribute.Name))
ctx.AddSource($"{data.ContainingClassSymbol}.Property.{data.Attribute.Name}.g", dependencyPropertySource);
if (_handledPropertyNames.Add(name))
{
var dependencyPropertySource = BuildProperty(data.ContainingClassSymbol, data.Attribute.Name, data.Attribute.TypeName, data.Type);
ctx.AddSource(name, dependencyPropertySource);
}
});

}
Expand Down Expand Up @@ -109,7 +108,6 @@ public partial class {containingClassSymbol.Name} : {typeof(IToolkitSampleGenera
item.PropertyChanged -= OnPropertyChanged;
}}


if (!(value is null))
{{
foreach (var item in value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Page x:Class="ProjectTemplate.Sample.ProjectTemplateFirstSamplePage"
<Page x:Class="ProjectTemplate.Sample.BackedTemplatedControlSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:ProjectTemplate.Sample"
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel>
<TextBlock x:Name="PrimaryText"
FontFamily="{x:Bind TextFontFamily, Mode=OneWay}"
FontSize="{x:Bind TextSize, Mode=OneWay}"
Foreground="{x:Bind TextForeground, Mode=OneWay}"
Text="Add sample here."
Visibility="{x:Bind IsTextVisible, Mode=OneWay}" />

<StackPanel Padding="20"
Spacing="15">
<labs:ProjectTemplate_xBind FontFamily="{x:Bind TextFontFamily, Mode=OneWay}"
FontSize="{x:Bind TextSize, Mode=OneWay}"
Foreground="{x:Bind TextForeground, Mode=OneWay}"
Visibility="{x:Bind IsTextVisible, Mode=OneWay}" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace ProjectTemplate.Sample;

[ToolkitSampleBoolOption("IsTextVisible", "IsVisible", true)]
// Single values without a colon are used for both label and value.
// To provide a different label for the value, separate with a colon surrounded by a single space on both sides ("label : value").
[ToolkitSampleMultiChoiceOption("TextSize", title: "Text size", "Small : 12", "Normal : 16", "Big : 32")]
[ToolkitSampleMultiChoiceOption("TextFontFamily", title: "Font family", "Segoe UI", "Arial", "Consolas")]
[ToolkitSampleMultiChoiceOption("TextForeground", title: "Text foreground",
"Teal : #0ddc8c",
"Sand : #e7a676",
"Dull green : #5d7577")]

[ToolkitSample(id: nameof(BackedTemplatedControlSample), "Backed templated control", description: "A sample for showing how to create and use a templated control with a backed resource dictionary.")]
public sealed partial class BackedTemplatedControlSample : Page
{
public BackedTemplatedControlSample()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Page x:Class="ProjectTemplate.Sample.BackedTemplatedControlWithCustomStyleSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Import custom styles -->
<labs:ProjectTemplateStyle_xBind />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>

<StackPanel Padding="20"
Spacing="15">
<labs:ProjectTemplate_xBind FontFamily="{x:Bind TextFontFamily, Mode=OneWay}"
FontSize="{x:Bind TextSize, Mode=OneWay}"
Foreground="{x:Bind TextForeground, Mode=OneWay}"
Style="{StaticResource CustomTemplatedControlStyle}"
Visibility="{x:Bind IsTextVisible, Mode=OneWay}" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace ProjectTemplate.Sample;

[ToolkitSampleBoolOption("IsTextVisible", "IsVisible", true)]
// Single values without a colon are used for both label and value.
// To provide a different label for the value, separate with a colon surrounded by a single space on both sides ("label : value").
[ToolkitSampleMultiChoiceOption("TextSize", title: "Text size", "Small : 12", "Normal : 16", "Big : 32")]
[ToolkitSampleMultiChoiceOption("TextFontFamily", title: "Font family", "Segoe UI", "Arial", "Consolas")]
[ToolkitSampleMultiChoiceOption("TextForeground", title: "Text foreground",
"Teal : #0ddc8c",
"Sand : #e7a676",
"Dull green : #5d7577")]

[ToolkitSample(id: nameof(BackedTemplatedControlWithCustomStyleSample), "Backed templated control (restyled)", description: "A sample for showing how to create and use a templated control with a backed resource dictionary and a custom style.")]
public sealed partial class BackedTemplatedControlWithCustomStyleSample : Page
{
public BackedTemplatedControlWithCustomStyleSample()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,31 @@
</ItemGroup>
<ItemGroup>
<None Remove="ProjectTemplate.md" />
<None Remove="ProjectTemplateFirstSamplePage.xaml" />
<None Remove="TemplatedControlStyle.xaml" />
<None Remove="TemplatedControlWithCustomStyleSample.xaml" />
<None Remove="BackedTemplatedControlWithCustomStyleSample.xaml" />
<None Remove="BackedTemplatedControlSample.xaml" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="*.md" />
</ItemGroup>
<ItemGroup>
<Content Remove="ProjectTemplate.md" />
</ItemGroup>
<ItemGroup>
<Compile Update="TemplatedControlStyle.xaml.cs">
<DependentUpon>TemplatedControlStyle.xaml</DependentUpon>
</Compile>
<Compile Update="TemplatedControlWithCustomStyleSample.xaml.cs">
<DependentUpon>TemplatedControlWithCustomStyleSample.xaml</DependentUpon>
</Compile>
<Compile Update="BackedTemplatedControlWithCustomStyleSample.xaml.cs">
<DependentUpon>BackedTemplatedControlWithCustomStyleSample.xaml</DependentUpon>
</Compile>
<Compile Update="BackedTemplatedControlSample.xaml.cs">
<DependentUpon>BackedTemplatedControlSample.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\CommunityToolkit.Labs.WinUI.ProjectTemplate.csproj" />
</ItemGroup>
Expand Down
20 changes: 19 additions & 1 deletion template/lab/samples/ProjectTemplate.Sample/ProjectTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@ For more information about this experiment see:

TODO: Fill in information about this experiment and how to get started here...

> [!SAMPLE ProjectTemplateFirstSamplePage]

# Templated Controls
### Implict style

> [!SAMPLE TemplatedControlSample]

### Custom style

> [!SAMPLE TemplatedControlWithCustomStyleSample]

# Templated Controls with x:Bind
### Implict style

> [!SAMPLE BackedTemplatedControlSample]

### Custom style

> [!SAMPLE BackedTemplatedControlWithCustomStyleSample]

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Page x:Class="ProjectTemplate.Sample.TemplatedControlSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel Padding="20"
Spacing="15">
<labs:ProjectTemplate_ClassicBinding FontFamily="{x:Bind TextFontFamily, Mode=OneWay}"
FontSize="{x:Bind TextSize, Mode=OneWay}"
Foreground="{x:Bind TextForeground, Mode=OneWay}"
Visibility="{x:Bind IsTextVisible, Mode=OneWay}" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace ProjectTemplate.Sample;
"Sand : #e7a676",
"Dull green : #5d7577")]

[ToolkitSample(id: nameof(ProjectTemplateFirstSamplePage), "Simple Options", description: "A sample page for showing how to do simple options.")]
public sealed partial class ProjectTemplateFirstSamplePage : Page
[ToolkitSample(id: nameof(TemplatedControlSample), "Templated control", description: "A sample for showing how to create and use a templated control.")]
public sealed partial class TemplatedControlSample : Page
{
public ProjectTemplateFirstSamplePage()
public TemplatedControlSample()
{
this.InitializeComponent();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Page x:Class="ProjectTemplate.Sample.TemplatedControlWithCustomStyleSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:labs="using:CommunityToolkit.Labs.WinUI"
xmlns:local="using:ProjectTemplate.Sample"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Import custom styles -->
<ResourceDictionary Source="ms-appx:///CommunityToolkit.Labs.WinUI.ProjectTemplate/ProjectTemplateStyle_ClassicBinding.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>

<StackPanel Padding="20"
Spacing="15">
<labs:ProjectTemplate_ClassicBinding FontFamily="{x:Bind TextFontFamily, Mode=OneWay}"
FontSize="{x:Bind TextSize, Mode=OneWay}"
Foreground="{x:Bind TextForeground, Mode=OneWay}"
Style="{StaticResource CustomTemplatedControlStyle}"
Visibility="{x:Bind IsTextVisible, Mode=OneWay}" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace ProjectTemplate.Sample;

[ToolkitSampleBoolOption("IsTextVisible", "IsVisible", true)]
// Single values without a colon are used for both label and value.
// To provide a different label for the value, separate with a colon surrounded by a single space on both sides ("label : value").
[ToolkitSampleMultiChoiceOption("TextSize", title: "Text size", "Small : 12", "Normal : 16", "Big : 32")]
[ToolkitSampleMultiChoiceOption("TextFontFamily", title: "Font family", "Segoe UI", "Arial", "Consolas")]
[ToolkitSampleMultiChoiceOption("TextForeground", title: "Text foreground",
"Teal : #0ddc8c",
"Sand : #e7a676",
"Dull green : #5d7577")]

[ToolkitSample(id: nameof(TemplatedControlWithCustomStyleSample), "Templated control (restyled)", description: "A sample for showing how to create a use and templated control with a custom style.")]
public sealed partial class TemplatedControlWithCustomStyleSample : Page
{
public TemplatedControlWithCustomStyleSample()
{
this.InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
<Name>ProjectTemplate.Sample</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@
<Page Remove="obj\bin\**" />
<UpToDateCheckInput Remove="obj\bin\**" />
</ItemGroup>
<ItemGroup>
<None Remove="ProjectTemplateStyle_ClassicBinding.xaml" />
<None Remove="ProjectTemplateStyle_xBind.xaml" />
</ItemGroup>
<ItemGroup>
<UpToDateCheckInput Remove="ProjectTemplateStyle_ClassicBinding.xaml" />
<UpToDateCheckInput Remove="ProjectTemplateStyle_xBind.xaml" />
</ItemGroup>
<ItemGroup>
<Compile Update="ProjectTemplateStyle_xBind.xaml.cs">
<DependentUpon>ProjectTemplateStyle_xBind.xaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
9 changes: 0 additions & 9 deletions template/lab/src/ProjectTemplate.cs

This file was deleted.

59 changes: 59 additions & 0 deletions template/lab/src/ProjectTemplateStyle_ClassicBinding.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:labs="using:CommunityToolkit.Labs.WinUI">

<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="MyBrush" Color="#000000" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<SolidColorBrush x:Key="MyBrush" Color="{StaticResource SystemBaseMediumColor}" />
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<SolidColorBrush x:Key="MyBrush" Color="{ThemeResource SystemColorButtonFaceColor}" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<Thickness x:Key="DefaultTemplatedControlItemPadding">4,4,4,4</Thickness>

<!-- Implicitly applied default style -->
<Style BasedOn="{StaticResource DefaultTemplatedControlStyle}" TargetType="labs:ProjectTemplate_ClassicBinding" />

<Style x:Key="DefaultTemplatedControlStyle" TargetType="labs:ProjectTemplate_ClassicBinding">
<Style.Setters>
<Setter Property="MyProperty" Value="This property has been overriden by the style template" />
<Setter Property="ItemPadding" Value="{StaticResource DefaultTemplatedControlItemPadding}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="labs:ProjectTemplate_ClassicBinding">
<Grid Padding="{TemplateBinding ItemPadding}">
<StackPanel Spacing="20">
<TextBlock
x:Name="PART_HelloWorld"
Foreground="{ThemeResource MyBrush}"
Text="Hello world!" />

<TextBlock Text="{TemplateBinding MyProperty}" />
<TextBlock Text="{Binding MyProperty, RelativeSource={RelativeSource Mode=TemplatedParent}}" Visibility="Collapsed" />
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>

<!-- Minimal, custom style -->
<Style
x:Key="CustomTemplatedControlStyle"
BasedOn="{StaticResource DefaultTemplatedControlStyle}"
TargetType="labs:ProjectTemplate_ClassicBinding">
<Style.Setters>
<Setter Property="MyProperty" Value="This property has been overriden by a custom style!" />
<Setter Property="ItemPadding" Value="25" />
</Style.Setters>
</Style>

</ResourceDictionary>
Loading