Skip to content

Commit ae8fe9d

Browse files
committed
AccentExtractor proof of concept pixel retrieval
1 parent cd1c057 commit ae8fe9d

18 files changed

+137
-447
lines changed

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractor.md

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,4 @@ TODO: Fill in information about this experiment and how to get started here...
2929
You can inherit from an existing component as well, like `Panel`, this example shows a control without a
3030
XAML Style that will be more light-weight to consume by an app developer:
3131

32-
> [!Sample Extensions.AccentExtractorCustomSample]
33-
34-
## Templated Controls
35-
36-
The Toolkit is built with templated controls. This provides developers a flexible way to restyle components
37-
easily while still inheriting the general functionality a control provides. The examples below show
38-
how a component can use a default style and then get overridden by the end developer.
39-
40-
TODO: Two types of templated control building methods are shown. Delete these if you're building a custom component.
41-
Otherwise, pick one method for your component and delete the files related to the unchosen `_ClassicBinding` or `_xBind`
42-
classes (and the custom non-suffixed one as well). Then, rename your component to just be your component name.
43-
44-
The `_ClassicBinding` class shows the traditional method used to develop components with best practices.
45-
46-
### Implict style
47-
48-
> [!SAMPLE Extensions.AccentExtractorTemplatedSample]
49-
50-
### Custom style
51-
52-
> [!SAMPLE Extensions.AccentExtractorTemplatedStyleCustomSample]
53-
54-
## Templated Controls with x:Bind
55-
56-
This is an _experimental_ new way to define components which allows for the use of x:Bind within the style.
57-
58-
### Implict style
59-
60-
> [!SAMPLE Extensions.AccentExtractorXbindBackedSample]
61-
62-
### Custom style
63-
64-
> [!SAMPLE Extensions.AccentExtractorXbindBackedStyleCustomSample]
65-
32+
> [!Sample AccentExtractorCustomSample]
Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
<!-- 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. -->
2-
<Page x:Class="Extensions.AccentExtractorExperiment.Samples.Extensions.AccentExtractorCustomSample"
1+
<!-- 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. -->
2+
<Page x:Class="Extensions.AccentExtractorExperiment.Samples.AccentExtractorCustomSample"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
5+
xmlns:extensions="using:CommunityToolkit.WinUI.Extensions"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:local="using:Extensions.AccentExtractorExperiment.Samples"
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
99
mc:Ignorable="d">
1010

11-
<StackPanel Spacing="16">
12-
<TextBlock Style="{StaticResource BodyStrongTextBlockStyle}"
13-
Text="{x:Bind TitleText, Mode=OneWay}" />
14-
<StackPanel Spacing="16">
15-
<controls:Extensions.AccentExtractor Orientation="{x:Bind local:Extensions.AccentExtractorCustomSample.ConvertStringToOrientation(LayoutOrientation), Mode=OneWay}">
16-
<TextBlock Text="1" />
17-
<TextBlock Text="2" />
18-
<TextBlock Text="3" />
19-
<TextBlock Text="4" />
20-
<TextBlock Text="5" />
21-
<TextBlock Text="6" />
22-
</controls:Extensions.AccentExtractor>
23-
</StackPanel>
24-
</StackPanel>
11+
<Grid>
12+
<Grid.ColumnDefinitions>
13+
<ColumnDefinition Width="*" />
14+
<ColumnDefinition Width="*" />
15+
</Grid.ColumnDefinitions>
16+
17+
<Image x:Name="AccentedImage"
18+
Source="/Extensions.AccentExtractorExperiment.Samples/Assets/icon.png"
19+
Stretch="UniformToFill"
20+
HorizontalAlignment="Center"
21+
VerticalAlignment="Center"
22+
Width="200"
23+
Height="200"
24+
Margin="20"
25+
extensions:AccentExtractor.CalculateAccent="True"/>
26+
27+
<Rectangle Grid.Column="1"
28+
HorizontalAlignment="Center"
29+
VerticalAlignment="Center"
30+
Width="200"
31+
Height="200"
32+
Margin="20">
33+
<Rectangle.Fill>
34+
<SolidColorBrush Color="{Binding Path=(extensions:AccentExtractor.AccentColor), ElementName=AccentedImage, Mode=OneWay}"/>
35+
</Rectangle.Fill>
36+
</Rectangle>
37+
</Grid>
2538
</Page>

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorCustomSample.xaml.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@ namespace Extensions.AccentExtractorExperiment.Samples;
99
/// <summary>
1010
/// An example sample page of a custom control inheriting from Panel.
1111
/// </summary>
12-
[ToolkitSampleTextOption("TitleText", "This is a title", Title = "Input the text")]
13-
[ToolkitSampleMultiChoiceOption("LayoutOrientation", "Horizontal", "Vertical", Title = "Orientation")]
14-
15-
[ToolkitSample(id: nameof(Extensions.AccentExtractorCustomSample), "Custom control", description: $"A sample for showing how to create and use a {nameof(Extensions.AccentExtractor)} custom control.")]
16-
public sealed partial class Extensions.AccentExtractorCustomSample : Page
12+
[ToolkitSample(id: nameof(AccentExtractorCustomSample), "Custom control", description: $"A sample for showing how ")]
13+
public sealed partial class AccentExtractorCustomSample : Page
1714
{
18-
public Extensions.AccentExtractorCustomSample()
15+
public AccentExtractorCustomSample()
1916
{
2017
this.InitializeComponent();
2118
}
22-
23-
// TODO: See https://github.com/CommunityToolkit/Labs-Windows/issues/149
24-
public static Orientation ConvertStringToOrientation(string orientation) => orientation switch
25-
{
26-
"Vertical" => Orientation.Vertical,
27-
"Horizontal" => Orientation.Horizontal,
28-
_ => throw new System.NotImplementedException(),
29-
};
3019
}

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorTemplatedSample.xaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorTemplatedSample.xaml.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorTemplatedStyleCustomSample.xaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorTemplatedStyleCustomSample.xaml.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorXbindBackedSample.xaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorXbindBackedSample.xaml.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractorXbindBackedStyleCustomSample.xaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)