Skip to content

Commit 549b220

Browse files
committed
Moved AccentExtractor from attached properties to DependencyObject
1 parent b9d756c commit 549b220

10 files changed

+224
-152
lines changed

components/Extensions.AccentExtractor/samples/Extensions.AccentExtractor.md renamed to components/Extensions.AccentExtractor/samples/AccentExtractor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +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 AccentExtractorCustomSample]
32+
> [!Sample AccentExtractorSample]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.AccentExtractorSample"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:extensions="using:CommunityToolkit.WinUI.Extensions"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="using:Extensions.AccentExtractorExperiment.Samples"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:behaviors="using:CommunityToolkit.WinUI.Behaviors"
10+
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
11+
mc:Ignorable="d">
12+
13+
<Page.Resources>
14+
<extensions:AccentExtractor x:Name="AccentAnalyzer" Source="{x:Bind AccentedImage}"/>
15+
</Page.Resources>
16+
17+
<Grid>
18+
<Grid.ColumnDefinitions>
19+
<ColumnDefinition Width="*" />
20+
<ColumnDefinition Width="*" />
21+
</Grid.ColumnDefinitions>
22+
23+
<Image x:Name="AccentedImage"
24+
Source="/Extensions.AccentExtractorExperiment.Samples/Assets/icon.png"
25+
Stretch="UniformToFill"
26+
HorizontalAlignment="Center"
27+
VerticalAlignment="Center"
28+
Width="200"
29+
Height="200"
30+
Margin="20">
31+
<interactivity:Interaction.Behaviors>
32+
<interactivity:EventTriggerBehavior EventName="ImageOpened">
33+
<interactivity:InvokeCommandAction Command="{x:Bind AccentAnalyzer.AccentUpdateCommand}"/>
34+
</interactivity:EventTriggerBehavior>
35+
</interactivity:Interaction.Behaviors>
36+
</Image>
37+
38+
<StackPanel Orientation="Vertical" Grid.Column="1"
39+
Width="200" HorizontalAlignment="Center"
40+
VerticalAlignment="Center"
41+
Spacing="8" Margin="20">
42+
<Rectangle Height="240">
43+
<Rectangle.Fill>
44+
<SolidColorBrush Color="{x:Bind AccentAnalyzer.PrimaryAccentColor, Mode=OneWay}"/>
45+
</Rectangle.Fill>
46+
</Rectangle>
47+
<Rectangle Height="120">
48+
<Rectangle.Fill>
49+
<SolidColorBrush Color="{x:Bind AccentAnalyzer.SecondaryAccentColor, Mode=OneWay}"/>
50+
</Rectangle.Fill>
51+
</Rectangle>
52+
<Rectangle Height="60">
53+
<Rectangle.Fill>
54+
<SolidColorBrush Color="{x:Bind AccentAnalyzer.TertiaryAccentColor, Mode=OneWay}"/>
55+
</Rectangle.Fill>
56+
</Rectangle>
57+
</StackPanel>
58+
</Grid>
59+
</Page>
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@ namespace Extensions.AccentExtractorExperiment.Samples;
99
/// <summary>
1010
/// An example sample page of a custom control inheriting from Panel.
1111
/// </summary>
12-
[ToolkitSample(id: nameof(AccentExtractorCustomSample), "Custom control", description: $"A sample for showing how ")]
13-
public sealed partial class AccentExtractorCustomSample : Page
12+
[ToolkitSample(id: nameof(AccentExtractorSample), "Accent Extractor Extensions", description: $"A sample for showing how the accent extractor can be used.")]
13+
public sealed partial class AccentExtractorSample : Page
1414
{
15-
public AccentExtractorCustomSample()
15+
public AccentExtractorSample()
1616
{
1717
this.InitializeComponent();
1818
}
19-
20-
private void Button_Click(object sender, RoutedEventArgs e)
21-
{
22-
AccentedImage.Source = new BitmapImage(new Uri(UrlTextbox.Text));
23-
}
2419
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<UserControl
2+
x:Class="Extensions.AccentExtractorExperiment.Samples.AccentExtractorSampleOptionsPane"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Extensions.AccentExtractorExperiment.Samples"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d">
9+
10+
<StackPanel Orientation="Horizontal">
11+
<TextBox x:Name="UrlTextbox" PlaceholderText="Enter a url"/>
12+
<Button Content="Set Image" Click="Button_Click"/>
13+
</StackPanel>
14+
</UserControl>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.UI.Xaml.Media.Imaging;
6+
7+
namespace Extensions.AccentExtractorExperiment.Samples;
8+
9+
[ToolkitSampleOptionsPane(nameof(AccentExtractorSample))]
10+
public partial class AccentExtractorSampleOptionsPane : UserControl
11+
{
12+
private AccentExtractorSample.XamlNamedPropertyRelay _sample;
13+
14+
public AccentExtractorSampleOptionsPane(AccentExtractorSample sample)
15+
{
16+
this.InitializeComponent();
17+
18+
_sample = new AccentExtractorSample.XamlNamedPropertyRelay(sample);
19+
}
20+
21+
private void Button_Click(object sender, RoutedEventArgs e)
22+
{
23+
_sample.AccentedImage.Source = new BitmapImage(new Uri(UrlTextbox.Text));
24+
}
25+
}

components/Extensions.AccentExtractor/samples/Dependencies.props

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,14 @@
99
For UWP / WinAppSDK / Uno packages, place the package references here.
1010
-->
1111
<Project>
12-
<!-- WinUI 2 / UWP -->
13-
<ItemGroup Condition="'$(IsUwp)' == 'true'">
14-
<!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> -->
15-
</ItemGroup>
16-
17-
<!-- WinUI 2 / Uno -->
18-
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
12+
<!-- WinUI 2 -->
13+
<ItemGroup Condition="'$(WinUIMajorVersion)' == '2'">
1914
<!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> -->
15+
<PackageReference Include="CommunityToolkit.Uwp.Behaviors" Version="8.2.250402"/>
2016
</ItemGroup>
21-
22-
<!-- WinUI 3 / WinAppSdk -->
23-
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
24-
<!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> -->
25-
</ItemGroup>
26-
27-
<!-- WinUI 3 / Uno -->
28-
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
29-
<!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> -->
17+
18+
<!-- WinUI 3 -->
19+
<ItemGroup Condition="'$(WinUIMajorVersion)' == '3'">
20+
<PackageReference Include="CommunityToolkit.WinUI.Behaviors" Version="8.2.250402"/>
3021
</ItemGroup>
3122
</Project>

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

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

components/Extensions.AccentExtractor/src/AccentExtractor.Clustering.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace CommunityToolkit.WinUI.Extensions;
88

9-
public static partial class AccentExtractor
9+
public partial class AccentExtractor
1010
{
1111
private static Vector3[] KMeansCluster(Span<Vector3> points, int k)
1212
{

0 commit comments

Comments
 (0)