Skip to content

Commit 950b543

Browse files
Merge pull request #95 from atc-net/feature/Optimize-Helpers-for-Brush-and-Color
Feature/optimize helpers for brush and color
2 parents b1ac89d + 4a92d0a commit 950b543

File tree

42 files changed

+2086
-709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2086
-709
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<ItemGroup Label="Code Analyzers">
4646
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
4747
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
48-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.120" PrivateAssets="All" />
48+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.122" PrivateAssets="All" />
4949
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
5050
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
5151
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.15.0.81779" PrivateAssets="All" />

docs/ColorCodes.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Color Codes
2+
3+
| Color-Key | Hex code |
4+
|-|-|
5+
| AliceBlue | 0xFFF0F8FF |
6+
| AntiqueWhite | 0xFFFAEBD7 |
7+
| Aqua | 0xFF00FFFF |
8+
| Aquamarine | 0xFF7FFFD4 |
9+
| Azure | 0xFFF0FFFF |
10+
| Beige | 0xFFF5F5DC |
11+
| Bisque | 0xFFFFE4C4 |
12+
| Black | 0xFF000000 |
13+
| BlanchedAlmond | 0xFFFFEBCD |
14+
| Blue | 0xFF0000FF |
15+
| BlueViolet | 0xFF8A2BE2 |
16+
| Brown | 0xFFA52A2A |
17+
| BurlyWood | 0xFFDEB887 |
18+
| CadetBlue | 0xFF5F9EA0 |
19+
| Chartreuse | 0xFF7FFF00 |
20+
| Chocolate | 0xFFD2691E |
21+
| Coral | 0xFFFF7F50 |
22+
| CornflowerBlue | 0xFF6495ED |
23+
| Cornsilk | 0xFFFFF8DC |
24+
| Crimson | 0xFFDC143C |
25+
| Cyan | 0xFF00FFFF |
26+
| DarkBlue | 0xFF00008B |
27+
| DarkCyan | 0xFF008B8B |
28+
| DarkGoldenrod | 0xFFB8860B |
29+
| DarkGray | 0xFFA9A9A9 |
30+
| DarkGreen | 0xFF006400 |
31+
| DarkKhaki | 0xFFBDB76B |
32+
| DarkMagenta | 0xFF8B008B |
33+
| DarkOliveGreen | 0xFF556B2F |
34+
| DarkOrange | 0xFFFF8C00 |
35+
| DarkOrchid | 0xFF9932CC |
36+
| DarkRed | 0xFF8B0000 |
37+
| DarkSalmon | 0xFFE9967A |
38+
| DarkSeaGreen | 0xFF8FBC8F |
39+
| DarkSlateBlue | 0xFF483D8B |
40+
| DarkSlateGray | 0xFF2F4F4F |
41+
| DarkTurquoise | 0xFF00CED1 |
42+
| DarkViolet | 0xFF9400D3 |
43+
| DeepPink | 0xFFFF1493 |
44+
| DeepSkyBlue | 0xFF00BFFF |
45+
| DimGray | 0xFF696969 |
46+
| DodgerBlue | 0xFF1E90FF |
47+
| Firebrick | 0xFFB22222 |
48+
| FloralWhite | 0xFFFFFAF0 |
49+
| ForestGreen | 0xFF228B22 |
50+
| Fuchsia | 0xFFFF00FF |
51+
| Gainsboro | 0xFFDCDCDC |
52+
| GhostWhite | 0xFFF8F8FF |
53+
| Gold | 0xFFFFD700 |
54+
| Goldenrod | 0xFFDAA520 |
55+
| Gray | 0xFF808080 |
56+
| Green | 0xFF008000 |
57+
| GreenYellow | 0xFFADFF2F |
58+
| Honeydew | 0xFFF0FFF0 |
59+
| HotPink | 0xFFFF69B4 |
60+
| IndianRed | 0xFFCD5C5C |
61+
| Indigo | 0xFF4B0082 |
62+
| Ivory | 0xFFFFFFF0 |
63+
| Khaki | 0xFFF0E68C |
64+
| Lavender | 0xFFE6E6FA |
65+
| LavenderBlush | 0xFFFFF0F5 |
66+
| LawnGreen | 0xFF7CFC00 |
67+
| LemonChiffon | 0xFFFFFACD |
68+
| LightBlue | 0xFFADD8E6 |
69+
| LightCoral | 0xFFF08080 |
70+
| LightCyan | 0xFFE0FFFF |
71+
| LightGoldenrodYellow | 0xFFFAFAD2 |
72+
| LightGreen | 0xFF90EE90 |
73+
| LightGray | 0xFFD3D3D3 |
74+
| LightPink | 0xFFFFB6C1 |
75+
| LightSalmon | 0xFFFFA07A |
76+
| LightSeaGreen | 0xFF20B2AA |
77+
| LightSkyBlue | 0xFF87CEFA |
78+
| LightSlateGray | 0xFF778899 |
79+
| LightSteelBlue | 0xFFB0C4DE |
80+
| LightYellow | 0xFFFFFFE0 |
81+
| Lime | 0xFF00FF00 |
82+
| LimeGreen | 0xFF32CD32 |
83+
| Linen | 0xFFFAF0E6 |
84+
| Magenta | 0xFFFF00FF |
85+
| Maroon | 0xFF800000 |
86+
| MediumAquamarine | 0xFF66CDAA |
87+
| MediumBlue | 0xFF0000CD |
88+
| MediumOrchid | 0xFFBA55D3 |
89+
| MediumPurple | 0xFF9370DB |
90+
| MediumSeaGreen | 0xFF3CB371 |
91+
| MediumSlateBlue | 0xFF7B68EE |
92+
| MediumSpringGreen | 0xFF00FA9A |
93+
| MediumTurquoise | 0xFF48D1CC |
94+
| MediumVioletRed | 0xFFC71585 |
95+
| MidnightBlue | 0xFF191970 |
96+
| MintCream | 0xFFF5FFFA |
97+
| MistyRose | 0xFFFFE4E1 |
98+
| Moccasin | 0xFFFFE4B5 |
99+
| NavajoWhite | 0xFFFFDEAD |
100+
| Navy | 0xFF000080 |
101+
| OldLace | 0xFFFDF5E6 |
102+
| Olive | 0xFF808000 |
103+
| OliveDrab | 0xFF6B8E23 |
104+
| Orange | 0xFFFFA500 |
105+
| OrangeRed | 0xFFFF4500 |
106+
| Orchid | 0xFFDA70D6 |
107+
| PaleGoldenrod | 0xFFEEE8AA |
108+
| PaleGreen | 0xFF98FB98 |
109+
| PaleTurquoise | 0xFFAFEEEE |
110+
| PaleVioletRed | 0xFFDB7093 |
111+
| PapayaWhip | 0xFFFFEFD5 |
112+
| PeachPuff | 0xFFFFDAB9 |
113+
| Peru | 0xFFCD853F |
114+
| Pink | 0xFFFFC0CB |
115+
| Plum | 0xFFDDA0DD |
116+
| PowderBlue | 0xFFB0E0E6 |
117+
| Purple | 0xFF800080 |
118+
| Red | 0xFFFF0000 |
119+
| RosyBrown | 0xFFBC8F8F |
120+
| RoyalBlue | 0xFF4169E1 |
121+
| SaddleBrown | 0xFF8B4513 |
122+
| Salmon | 0xFFFA8072 |
123+
| SandyBrown | 0xFFF4A460 |
124+
| SeaGreen | 0xFF2E8B57 |
125+
| SeaShell | 0xFFFFF5EE |
126+
| Sienna | 0xFFA0522D |
127+
| Silver | 0xFFC0C0C0 |
128+
| SkyBlue | 0xFF87CEEB |
129+
| SlateBlue | 0xFF6A5ACD |
130+
| SlateGray | 0xFF708090 |
131+
| Snow | 0xFFFFFAFA |
132+
| SpringGreen | 0xFF00FF7F |
133+
| SteelBlue | 0xFF4682B4 |
134+
| Tan | 0xFFD2B48C |
135+
| Teal | 0xFF008080 |
136+
| Thistle | 0xFFD8BFD8 |
137+
| Tomato | 0xFFFF6347 |
138+
| Transparent | 0x00FFFFFF |
139+
| Turquoise | 0xFF40E0D0 |
140+
| Violet | 0xFFEE82EE |
141+
| Wheat | 0xFFF5DEB3 |
142+
| White | 0xFFFFFFFF |
143+
| WhiteSmoke | 0xFFF5F5F5 |
144+
| Yellow | 0xFFFFFF00 |
145+
| YellowGreen | 0xFF9ACD32 |
146+
147+
## Notes
148+
149+
Cyan and Aqua has the same hex code (#FF00FFFF)
150+
Magenta and Fuchsia has the same hex code (#0xFFFF00FF)

sample/Atc.Wpf.Sample/App.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ await host
107107
GlobalizationConstants.EnglishCultureInfo,
108108
GlobalizationConstants.EnglishCultureInfo);
109109

110+
ColorHelper.InitializeWithSupportedLanguages();
111+
SolidColorBrushHelper.InitializeWithSupportedLanguages();
112+
110113
ThemeManager.Current.ChangeTheme(
111114
Current,
112115
"Light.Blue");

sample/Atc.Wpf.Sample/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
global using Atc.Wpf.Diagnostics;
3131
global using Atc.Wpf.FontIcons;
3232
global using Atc.Wpf.FontIcons.ValueConverters;
33+
global using Atc.Wpf.Helpers;
3334
global using Atc.Wpf.Messaging;
3435
global using Atc.Wpf.Mvvm;
3536
global using Atc.Wpf.Sample.Models;

src/Atc.Wpf.Controls/BaseControls/Internal/ToggleSwitchAutomationPeer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Atc.Wpf.Controls.BaseControls.Internal;
22

33
public class ToggleSwitchAutomationPeer : FrameworkElementAutomationPeer, IToggleProvider
44
{
5-
public ToggleSwitchAutomationPeer([NotNull] ToggleSwitch owner)
5+
public ToggleSwitchAutomationPeer(ToggleSwitch owner)
66
: base(owner)
77
{
88
}

src/Atc.Wpf.Controls/LabelControls/Extractors/ModelToLabelControlExtractor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ private static LabelWellKnownColorSelector CreateLabelColorSelector<T>(
625625
}
626626
else
627627
{
628-
var colorName = ColorUtil.GetColorNameFromHex(colorCode);
628+
var colorName = ColorHelper.GetColorNameFromHex(colorCode);
629629
defaultColorName = colorName ?? ((int)DropDownFirstItemType.PleaseSelect).ToString(GlobalizationConstants.EnglishCultureInfo);
630630
}
631631
}

src/Atc.Wpf.Controls/LabelControls/LabelCheckBox.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static void OnIsCheckedChanged(
3838
control,
3939
new ChangedBooleanEventArgs(
4040
control.Identifier,
41-
control.IsChecked,
42-
!control.IsChecked));
41+
!control.IsChecked,
42+
control.IsChecked));
4343
}
4444
}

src/Atc.Wpf.Controls/LabelControls/LabelControlsFormColumn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public Dictionary<string, object> GetKeyValues()
167167

168168
break;
169169
case LabelWellKnownColorSelector labelWellKnownColorSelector:
170-
var color = ColorUtil.GetColorFromName(labelWellKnownColorSelector.SelectedKey);
170+
var color = ColorHelper.GetColorFromName(labelWellKnownColorSelector.SelectedKey, GlobalizationConstants.EnglishCultureInfo);
171171
if (color is not null)
172172
{
173173
result.Add(control.GetFullIdentifier(), (Color)color);

src/Atc.Wpf.Controls/LabelControls/Selectors/LabelWellKnownColorSelector.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ private static void OnSelectedKeyLostFocus(
191191
return;
192192
}
193193

194+
control.lastSelectedKey = control.SelectedKey;
194195
if (control.isFirstOnSelectedKeyLostFocus)
195196
{
196197
control.isFirstOnSelectedKeyLostFocus = false;
197-
control.lastSelectedKey = control.SelectedKey;
198198
return;
199199
}
200200

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
namespace Atc.Wpf.Controls.Windows;
2+
3+
/// <summary>
4+
/// VisualHost.
5+
/// </summary>
6+
public class VisualHost : FrameworkElement
7+
{
8+
private readonly VisualCollection visualCollection;
9+
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="VisualHost" /> class.
12+
/// </summary>
13+
public VisualHost()
14+
{
15+
this.visualCollection = new VisualCollection(this);
16+
}
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="VisualHost" /> class.
20+
/// </summary>
21+
/// <param name="visual">The visual.</param>
22+
public VisualHost(
23+
Visual visual)
24+
: this()
25+
=> Add(visual);
26+
27+
/// <summary>
28+
/// Provide a required override for the VisualChildrenCount property.
29+
/// Gets the number of visual child elements within this element.
30+
/// </summary>
31+
/// <returns>The number of visual child elements for this element.</returns>
32+
protected override int VisualChildrenCount => visualCollection.Count;
33+
34+
/// <summary>
35+
/// Adds the specified visual.
36+
/// </summary>
37+
/// <param name="visual">The visual.</param>
38+
public void Add(
39+
Visual visual)
40+
{
41+
ArgumentNullException.ThrowIfNull(visual);
42+
43+
visualCollection.Add(visual);
44+
}
45+
46+
/// <summary>
47+
/// Clears this instance.
48+
/// </summary>
49+
public void Clear()
50+
=> visualCollection.Clear();
51+
52+
/// <summary>
53+
/// Provide a required override for the GetVisualChild method.
54+
/// Overrides <see cref="GetVisualChild(int)" />, and returns a child at the specified index from a collection of child elements.
55+
/// </summary>
56+
/// <param name="index">The zero-based index of the requested child element in the collection.</param>
57+
/// <returns>
58+
/// The requested child element. This should not return null; if the provided index is out of range, an exception is thrown.
59+
/// </returns>
60+
protected override Visual GetVisualChild(
61+
int index)
62+
{
63+
if (index < 0 || index >= visualCollection.Count)
64+
{
65+
throw new ArgumentOutOfRangeException(nameof(index));
66+
}
67+
68+
return visualCollection[index];
69+
}
70+
}

src/Atc.Wpf.Theming/Automation/Peers/WindowCommandsAutomationPeer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ReSharper disable SuggestBaseTypeForParameterInConstructor
2-
32
namespace Atc.Wpf.Theming.Automation.Peers;
43

54
public class WindowCommandsAutomationPeer : FrameworkElementAutomationPeer

src/Atc.Wpf.Theming/Controls/Selectors/AccentColorSelector.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
IsSynchronizedWithCurrentItem="True"
1919
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Items}"
2020
SelectedValue="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=SelectedKey, Mode=TwoWay}"
21-
SelectedValuePath="Name">
21+
SelectedValuePath="Key">
2222
<ComboBox.ItemTemplate>
2323
<DataTemplate>
2424
<StackPanel Orientation="Horizontal">

src/Atc.Wpf.Theming/Controls/Selectors/ColorItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace Atc.Wpf.Theming.Controls.Selectors;
22

33
public record ColorItem(
4-
string Name,
4+
string Key,
55
string DisplayName,
66
string DisplayHexCode,
77
Brush BorderColorBrush,

src/Atc.Wpf.Theming/Controls/Selectors/WellKnownColorSelector.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
x:Name="CbColors"
2222
ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Items}"
2323
SelectedValue="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=SelectedKey, Mode=TwoWay}"
24-
SelectedValuePath="Name"
24+
SelectedValuePath="Key"
2525
SelectionChanged="OnSelectionChanged">
2626
<ComboBox.ItemContainerStyle>
2727
<Style TargetType="{x:Type ComboBoxItem}">

0 commit comments

Comments
 (0)