Skip to content

Commit 3a25d14

Browse files
committed
refactor inlineColorPicker with AP.labeledBy
1 parent f0a6a30 commit 3a25d14

4 files changed

Lines changed: 65 additions & 44 deletions

File tree

WinUIGallery/ControlPages/DesignGuidance/AccessibilityColorContrastPage.xaml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,46 +78,33 @@
7878
<ColumnDefinition Width="*" />
7979
</Grid.ColumnDefinitions>
8080

81-
<TextBlock
82-
Grid.Row="0"
83-
Grid.Column="0"
84-
Margin="12,0,0,0"
85-
VerticalAlignment="Bottom"
86-
Style="{ThemeResource BodyStrongTextBlockStyle}"
87-
Text="Text color" />
88-
8981
<controls1:InlineColorPicker
9082
x:Name="TextColorPicker"
91-
Grid.Row="1"
92-
Grid.Column="0"
93-
Margin="12,0,0,12"
83+
AutomationProperties.Name="TextColorPicker"
84+
Grid.RowSpan="2"
85+
Header="Text Color"
9486
ColorChanged="TextColorPicker_ColorChanged"
9587
Color="Black" />
9688

97-
<TextBlock
98-
Grid.Row="0"
99-
Grid.Column="1"
100-
Margin="12,10,0,0"
101-
Style="{ThemeResource BodyStrongTextBlockStyle}"
102-
Text="Background color" />
10389
<controls1:InlineColorPicker
10490
x:Name="BackgroundColorPicker"
105-
Grid.Row="1"
91+
AutomationProperties.Name="BackgroundColorPicker"
10692
Grid.Column="1"
107-
Margin="12,0,0,12"
93+
Grid.RowSpan="2"
94+
Header="Background Color"
10895
ColorChanged="BackgroundColorPicker_ColorChanged" />
10996

11097
<TextBlock
11198
Grid.Column="3"
11299
Margin="12,0,0,0"
113-
VerticalAlignment="Bottom"
100+
VerticalAlignment="Center"
114101
Style="{ThemeResource BodyStrongTextBlockStyle}"
115102
Text="Contrast Ratio" />
116103
<TextBlock
117104
x:Name="ContrastRatioPresenter"
118105
Grid.Row="1"
119106
Grid.Column="3"
120-
Margin="12,0,0,0"
107+
Margin="12,-4,0,0"
121108
Style="{ThemeResource SubtitleTextBlockStyle}"
122109
Text="21:1" />
123110

WinUIGallery/Controls/InlineColorPicker.xaml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,36 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
mc:Ignorable="d">
88

9-
<Grid ColumnSpacing="2">
9+
<Grid ColumnSpacing="2" Margin="12,12,0,12">
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="Auto" />
12+
<RowDefinition Height="Auto" />
13+
</Grid.RowDefinitions>
1014
<Grid.ColumnDefinitions>
1115
<ColumnDefinition Width="Auto"/>
1216
<ColumnDefinition Width="*"/>
1317
</Grid.ColumnDefinitions>
14-
<SplitButton Padding="0" VerticalAlignment="Stretch">
15-
<Rectangle x:Name="ColorPreview" Fill="{x:Bind ColorBrush, Mode=OneWay}" VerticalAlignment="Stretch" MinHeight="30" Width="40"/>
18+
19+
<TextBlock
20+
x:Name="HeaderText"
21+
Grid.Row="0"
22+
Grid.Column="0"
23+
Grid.ColumnSpan="2"
24+
Margin="0,0,0,12"
25+
VerticalAlignment="Bottom"
26+
Style="{ThemeResource BodyStrongTextBlockStyle}"
27+
Text="{x:Bind Header, Mode=OneWay}" />
28+
29+
<SplitButton
30+
AutomationProperties.LabeledBy="{Binding ElementName=HeaderText}"
31+
Padding="0" VerticalAlignment="Stretch"
32+
Grid.Row="1">
33+
<Rectangle
34+
x:Name="ColorPreview"
35+
Fill="{x:Bind ColorBrush, Mode=OneWay}"
36+
VerticalAlignment="Stretch"
37+
MinHeight="30"
38+
Width="40"/>
1639
<SplitButton.Flyout>
1740
<Flyout Opened="PickerFlyout_Opened">
1841
<ColorPicker x:Name="Picker"
@@ -23,6 +46,14 @@
2346
</Flyout>
2447
</SplitButton.Flyout>
2548
</SplitButton>
26-
<TextBox x:Name="ColorHex" TextChanged="ColorHex_TextChanged" MinWidth="120" HorizontalAlignment="Stretch" Margin="4, 0, 0, 0" Grid.Column="1"/>
49+
<TextBox
50+
x:Name="ColorHex"
51+
AutomationProperties.LabeledBy="{Binding ElementName=HeaderText}"
52+
TextChanged="ColorHex_TextChanged"
53+
MinWidth="120"
54+
HorizontalAlignment="Stretch"
55+
Margin="4,0,0,0"
56+
Grid.Column="1"
57+
Grid.Row="1" />
2758
</Grid>
2859
</UserControl>

WinUIGallery/Controls/InlineColorPicker.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Runtime.InteropServices.WindowsRuntime;
6+
using AppUIBasics.Controls;
67
using Microsoft.UI;
78
using Microsoft.UI.Xaml;
89
using Microsoft.UI.Xaml.Controls;
@@ -22,6 +23,15 @@ namespace WinUIGallery.DesktopWap.Controls
2223
{
2324
public sealed partial class InlineColorPicker : UserControl
2425
{
26+
public string Header
27+
{
28+
get { return (string)GetValue(HeaderProperty); }
29+
set { SetValue(HeaderProperty, value); }
30+
}
31+
32+
public static readonly DependencyProperty HeaderProperty =
33+
DependencyProperty.Register("Header", typeof(string), typeof(InlineColorPicker), new PropertyMetadata(null));
34+
2535
public Color Color
2636
{
2737
get { return (Color)GetValue(ColorProperty); }

WinUIGallery/WinUIGallery.csproj

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
<PackageReference Include="ColorCode.Core" />
5656
<PackageReference Include="Microsoft.Graphics.Win2D" />
5757
<PackageReference Include="Microsoft.Windows.CsWinRT" />
58-
<PackageReference Include="CommunityToolkit.Labs.WinUI.SegmentedControl"/>
59-
<PackageReference Include="CommunityToolkit.Labs.WinUI.SettingsControls"/>
60-
<PackageReference Include="CommunityToolkit.WinUI.UI"/>
61-
<PackageReference Include="CommunityToolkit.WinUI.UI.Animations"/>
58+
<PackageReference Include="CommunityToolkit.Labs.WinUI.SegmentedControl" />
59+
<PackageReference Include="CommunityToolkit.Labs.WinUI.SettingsControls" />
60+
<PackageReference Include="CommunityToolkit.WinUI.UI" />
61+
<PackageReference Include="CommunityToolkit.WinUI.UI.Animations" />
6262
<PackageReference Include="Microsoft.VCRTForwarders.140" />
6363
<Manifest Include="$(ApplicationManifest)" />
6464

@@ -70,22 +70,15 @@
7070
<PackageReference Include="System.Private.Uri" />
7171
</ItemGroup>
7272
<ItemGroup Condition="'$(IsInWinUIRepo)' != 'true'">
73-
<PackageReference Update="Microsoft.WindowsAppSDK" Version="$(WindowsAppSdkPackageVersion)" />
73+
<PackageReference Update="Microsoft.WindowsAppSDK" Version="1.4.230628000-preview1" />
7474
<PackageReference Remove="ColorCode.Core" />
75-
<PackageReference Include="ColorCode.WinUI"
76-
Version="$(ColorCodeVersion)" />
77-
<PackageReference Update="CommunityToolkit.Labs.WinUI.SegmentedControl"
78-
Version="$(CommunityToolkitSegmentedControlVersion)" />
79-
<PackageReference Update="CommunityToolkit.Labs.WinUI.SettingsControls"
80-
Version="$(CommunityToolkitSettingsControlsVersion)" />
81-
<PackageReference Update="CommunityToolkit.WinUI.UI"
82-
Version="$(CommunityToolkitWinUIVersion)" />
83-
<PackageReference Update="CommunityToolkit.WinUI.UI.Animations"
84-
Version="$(CommunityToolkitWinUIVersion)" />
85-
<PackageReference Update="Microsoft.Graphics.Win2D"
86-
Version="$(GraphicsWin2DVersion)" />
87-
<PackageReference Update="Microsoft.VCRTForwarders.140"
88-
Version="1.0.6" />
75+
<PackageReference Include="ColorCode.WinUI" Version="$(ColorCodeVersion)" />
76+
<PackageReference Update="CommunityToolkit.Labs.WinUI.SegmentedControl" Version="$(CommunityToolkitSegmentedControlVersion)" />
77+
<PackageReference Update="CommunityToolkit.Labs.WinUI.SettingsControls" Version="$(CommunityToolkitSettingsControlsVersion)" />
78+
<PackageReference Update="CommunityToolkit.WinUI.UI" Version="$(CommunityToolkitWinUIVersion)" />
79+
<PackageReference Update="CommunityToolkit.WinUI.UI.Animations" Version="$(CommunityToolkitWinUIVersion)" />
80+
<PackageReference Update="Microsoft.Graphics.Win2D" Version="$(GraphicsWin2DVersion)" />
81+
<PackageReference Update="Microsoft.VCRTForwarders.140" Version="1.0.6" />
8982
<!-- Get latest WinRT.Runtime.dll from C#/WinRT -->
9083
<PackageReference Update="Microsoft.Windows.CsWinRT" Version="2.0.3" />
9184
<PackageReference Update="System.Private.Uri" Version="4.3.2" />

0 commit comments

Comments
 (0)