├── .gitattributes
├── .gitignore
├── LICENSE.md
├── README.md
├── images
├── example-avalonia-1.png
├── example-avalonia-2.png
├── example-avalonia-3.png
├── example-wpf-1.png
├── example-wpf-2.png
├── example-wpf-3.png
├── example-wpf-4.png
└── example-wpf-mahapps-1.png
└── src
├── AvaloniaUI
├── Egorozh.ColorPicker.Avalonia.Dialog
│ ├── Controls
│ │ ├── ColorPickerButton.cs
│ │ ├── ColorPickerDialog.axaml
│ │ └── ColorPickerDialog.axaml.cs
│ ├── Egorozh.ColorPicker.Avalonia.Dialog.csproj
│ ├── Egorozh.ColorPicker.Avalonia.Dialog.csproj.DotSettings
│ └── Themes
│ │ ├── FluentTheme.axaml
│ │ ├── FluentTheme.axaml.cs
│ │ ├── SimpleTheme.axaml
│ │ └── SimpleTheme.axaml.cs
└── Egorozh.ColorPicker.Avalonia
│ ├── ColorPickerControl.cs
│ ├── Controls
│ ├── ColorEditor.cs
│ ├── ColorHexComboBox.cs
│ ├── ColorListItem.cs
│ ├── ColorPalette.cs
│ ├── ColorPickerButtonBase.cs
│ ├── ColorPreview.cs
│ ├── ColorWheel.cs
│ ├── NumUpDowns
│ │ ├── Base
│ │ │ └── LabelNumericUpDown.cs
│ │ ├── Hsv
│ │ │ ├── HueColorNumUpDown.cs
│ │ │ ├── SaturationColorNumUpDown.cs
│ │ │ └── ValueColorNumUpDown.cs
│ │ └── RgbaColorNumericUpDown.cs
│ └── Sliders
│ │ ├── Base
│ │ └── ColorSlider.cs
│ │ ├── Hsv
│ │ ├── HueColorSlider.cs
│ │ ├── SaturationColorSlider.cs
│ │ └── ValueColorSlider.cs
│ │ └── RgbaColorSlider.cs
│ ├── Egorozh.ColorPicker.Avalonia.csproj
│ ├── Egorozh.ColorPicker.Avalonia.csproj.DotSettings
│ ├── GlobalUsings.cs
│ ├── Helpers
│ └── ColorConvertExtensions.cs
│ ├── Themes
│ ├── Controls
│ │ ├── ColorPickerButton.axaml
│ │ ├── Default
│ │ │ ├── ColorEditor.axaml
│ │ │ ├── ColorHexComboBox.axaml
│ │ │ ├── ColorPalette.axaml
│ │ │ ├── ColorPicker.axaml
│ │ │ ├── ColorPreview.axaml
│ │ │ ├── ColorSlider.axaml
│ │ │ ├── ColorWheel.axaml
│ │ │ ├── LabelNumericUpDown.axaml
│ │ │ ├── ModeListBox.axaml
│ │ │ └── Tabs.axaml
│ │ └── Fluent
│ │ │ ├── ColorEditor.axaml
│ │ │ ├── ColorHexComboBox.axaml
│ │ │ ├── ColorPalette.axaml
│ │ │ ├── ColorPicker.axaml
│ │ │ ├── ColorPreview.axaml
│ │ │ ├── ColorSlider.axaml
│ │ │ ├── ColorWheel.axaml
│ │ │ ├── LabelNumericUpDown.axaml
│ │ │ ├── ModeListBox.axaml
│ │ │ └── Tabs.axaml
│ ├── Default.axaml
│ ├── Fluent.axaml
│ └── Others
│ │ ├── Brushes.axaml
│ │ └── Icons.axaml
│ └── ValueConverters
│ ├── AccentColorShadeConverter.cs
│ ├── Base
│ └── BaseValueConverter.cs
│ ├── ColorToSolidColorBrushConverter.cs
│ ├── DivideDoubleToCornerRadiusConverter.cs
│ └── DivideDoubleToDoubleConverter.cs
├── ColorPicker.sln
├── Core
└── ColorPicker.Shared
│ ├── ColorManager.cs
│ ├── ColorPicker.Shared.projitems
│ ├── ColorPicker.Shared.shproj
│ ├── Colors
│ ├── HslColor.cs
│ └── HsvColor.cs
│ ├── Core
│ ├── IColorClient.cs
│ └── IColorManager.cs
│ ├── Enums
│ └── RgbaChannel.cs
│ ├── Helpers
│ ├── ColorWheelHelpers.cs
│ └── HexComboBoxHelpers.cs
│ ├── Models
│ └── NamedColor.cs
│ └── Palette
│ ├── ColorPaletteType.cs
│ ├── ColorPalettes.cs
│ └── Serializers
│ ├── AdobeColorTablePaletteSerializer.cs
│ ├── AdobePhotoshopColorSwatchSerializer.cs
│ ├── Core
│ ├── IPaletteSerializer.cs
│ └── PaletteSerializer.cs
│ ├── GimpPaletteSerializer.cs
│ ├── InterleavedBitmapPaletteSerializer.cs
│ ├── JascPaletteSerializer.cs
│ ├── PaintNetPaletteSerializer.cs
│ └── RawPaletteSerializer.cs
├── Directory.Build.props
├── LICENSE.md
├── Samples
├── Egorozh.ColorPicker.Avalonia.Client
│ ├── App.axaml
│ ├── App.axaml.cs
│ ├── Assets
│ │ └── avalonia-logo.ico
│ ├── Egorozh.ColorPicker.Avalonia.Client.csproj
│ ├── Egorozh.ColorPicker.Avalonia.Client.csproj.DotSettings
│ ├── Program.cs
│ ├── Views
│ │ ├── MainWindow.axaml
│ │ └── MainWindow.axaml.cs
│ └── nuget.config
├── Egorozh.ColorPicker.WPF.Client
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AssemblyInfo.cs
│ ├── Egorozh.ColorPicker.WPF.Client.csproj
│ ├── MainWindow.xaml
│ └── MainWindow.xaml.cs
└── Egorozh.ColorPicker.WPF.MahApps.Client
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AssemblyInfo.cs
│ ├── Egorozh.ColorPicker.WPF.MahApps.Client.csproj
│ ├── MainWindow.xaml
│ └── MainWindow.xaml.cs
└── WPF
├── Egorozh.ColorPicker.WPF.Dialog.MahApps
├── AssemblyInfo.cs
├── Controls
│ ├── ColorPickerButton.cs
│ ├── ColorPickerDialog.xaml
│ └── ColorPickerDialog.xaml.cs
├── Egorozh.ColorPicker.WPF.Dialog.MahApps.csproj
├── Egorozh.ColorPicker.WPF.Dialog.MahApps.csproj.DotSettings
└── Themes
│ ├── Controls
│ ├── ColorHexComboBox.xaml
│ ├── ColorSlider.xaml
│ ├── LabelNumericUpDown.xaml
│ └── ModeListBox.xaml
│ └── Generic.xaml
├── Egorozh.ColorPicker.WPF.Dialog
├── Controls
│ ├── ColorPickerButton.cs
│ ├── ColorPickerDialog.xaml
│ └── ColorPickerDialog.xaml.cs
├── Egorozh.ColorPicker.WPF.Dialog.csproj
└── Egorozh.ColorPicker.WPF.Dialog.csproj.DotSettings
└── Egorozh.ColorPicker.WPF
├── AssemblyInfo.cs
├── ColorPickerControl.cs
├── Controls
├── ColorEditor.cs
├── ColorHexComboBox.cs
├── ColorPalette.cs
├── ColorPickerButtonBase.cs
├── ColorPreview.cs
├── ColorWheel.cs
├── NumUpDowns
│ ├── Base
│ │ ├── LabelNumericUpDown.cs
│ │ └── NumericUpDown.cs
│ ├── Hsv
│ │ ├── HueColorNumUpDown.cs
│ │ ├── SaturationColorNumUpDown.cs
│ │ └── ValueColorNumUpDown.cs
│ └── RgbaColorNumericUpDown.cs
├── ScreenColorPicker.cs
└── Sliders
│ ├── Base
│ └── ColorSlider.cs
│ ├── Hsv
│ ├── HueColorSlider.cs
│ ├── SaturationColorSlider.cs
│ └── ValueColorSlider.cs
│ └── RgbaColorSlider.cs
├── Egorozh.ColorPicker.WPF.csproj
├── Egorozh.ColorPicker.WPF.csproj.DotSettings
├── GlobalUsings.cs
├── Helpers
├── ColorConvertExtensions.cs
└── NativeMethods.cs
├── Resources
├── HsvWheelEffect.ps
└── eyedropper.cur
├── Themes
├── Controls
│ ├── ColorEditor.xaml
│ ├── ColorHexComboBox.xaml
│ ├── ColorPalette.xaml
│ ├── ColorPickerButton.xaml
│ ├── ColorPickerControl.xaml
│ ├── ColorPreview.xaml
│ ├── ColorSlider.xaml
│ ├── ColorWheel.xaml
│ ├── LabelNumericUpDown.xaml
│ ├── ModeListBox.xaml
│ ├── ScreenColorPicker.xaml
│ └── Tabs.xaml
├── Generic.xaml
└── Others
│ ├── Brushes.xaml
│ └── Icons.xaml
└── ValueConverters
├── AccentColorShadeConverter.cs
├── BoolToVisibilityConverter.cs
├── ColorToSolidColorBrushConverter.cs
├── DivideDoubleToCornerRadiusConverter.cs
└── DivideDoubleToDoubleConverter.cs
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Zheludkov Egor
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.nuget.org/packages/Egorozh.ColorPicker.Avalonia.Dialog/) [](https://www.nuget.org/packages/Egorozh.ColorPicker.WPF.Dialog/) [](https://www.nuget.org/packages/Egorozh.ColorPicker.WPF.Dialog.MahApps/)
2 |
3 | # Egorozh.ColorPicker
4 |
5 | ## AvaloniaUI ColorPicker:
6 | 
7 | 
8 | 
9 |
10 | ### AvaloniaUI Getting Started
11 |
12 | Install the library as a NuGet package:
13 |
14 | ```powershell
15 | Install-Package Egorozh.ColorPicker.Avalonia.Dialog
16 | # Or 'dotnet add package Egorozh.ColorPicker.Avalonia.Dialog'
17 | ```
18 |
19 | Then, reference the preffered theme from your `App.xaml` file:
20 |
21 | ```xml
22 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | ```
40 | Done! Use ColorPickerButton
41 | ```xml
42 |
44 | ```
45 | or ColorPickerDialog:
46 | ```c#
47 | ColorPickerDialog dialog = new ()
48 | {
49 | Color = _color
50 | };
51 |
52 | var res = await dialog.ShowDialog(Owner);
53 |
54 | if (res)
55 | _color = dialog.Color;
56 | ```
57 |
58 | ## WPF ColorPicker:
59 | 
60 | 
61 | 
62 | 
63 | 
64 |
65 | ### WPF Getting Started
66 |
67 | Install the library as a NuGet package:
68 |
69 | ```powershell
70 | Install-Package Egorozh.ColorPicker.WPF.Dialog
71 | # Or 'dotnet add package Egorozh.ColorPicker.WPF.Dialog'
72 | ```
73 | Done! Use ColorPickerButton
74 | ```xml
75 |
77 | ```
78 | or ColorPickerDialog:
79 | ```c#
80 | var dialog = new ColorPickerDialog
81 | {
82 | Owner = Owner,
83 | Color = Color
84 | };
85 |
86 | var res = dialog.ShowDialog();
87 |
88 | if (res == true)
89 | Color = dialog.Color;
90 | ```
91 | ### To run MahApps Version:
92 | Install the library as a NuGet package:
93 |
94 | ```powershell
95 | Install-Package Egorozh.ColorPicker.WPF.Dialog.MahApps
96 | # Or 'dotnet add Egorozh.ColorPicker.WPF.Dialog.MahApps'
97 | ```
98 | Then, reference the preffered theme from your `App.xaml` file:
99 |
100 | ```xml
101 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 | ```
121 |
--------------------------------------------------------------------------------
/images/example-avalonia-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-avalonia-1.png
--------------------------------------------------------------------------------
/images/example-avalonia-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-avalonia-2.png
--------------------------------------------------------------------------------
/images/example-avalonia-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-avalonia-3.png
--------------------------------------------------------------------------------
/images/example-wpf-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-wpf-1.png
--------------------------------------------------------------------------------
/images/example-wpf-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-wpf-2.png
--------------------------------------------------------------------------------
/images/example-wpf-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-wpf-3.png
--------------------------------------------------------------------------------
/images/example-wpf-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-wpf-4.png
--------------------------------------------------------------------------------
/images/example-wpf-mahapps-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/egorozh/Egorozh.ColorPicker/afc29979288300121aba52aeb283b8b22ce432c7/images/example-wpf-mahapps-1.png
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Controls/ColorPickerButton.cs:
--------------------------------------------------------------------------------
1 | using System.Threading.Tasks;
2 |
3 | namespace Egorozh.ColorPicker.Dialog;
4 |
5 | public class ColorPickerButton : ColorPickerButtonBase
6 | {
7 | protected override async Task ChangeColor()
8 | {
9 | ColorPickerDialog dialog = new()
10 | {
11 | Color = Color,
12 | Colors = Colors
13 | };
14 |
15 | var res = await dialog.ShowDialog(Owner);
16 |
17 | if (res)
18 | Color = dialog.Color;
19 | }
20 | }
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Controls/ColorPickerDialog.axaml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
25 |
26 |
29 |
30 |
34 |
35 |
40 |
41 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Egorozh.ColorPicker.Avalonia.Dialog.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net7.0;net8.0
5 |
6 | Egorozh.ColorPicker.Dialog
7 |
8 | true
9 |
10 | Color, ColorPicker, Avalonia, AvaloniaUI
11 | LICENSE.md
12 | README.md
13 | ColorPicker dialog for Avalonia
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Egorozh.ColorPicker.Avalonia.Dialog.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | True
3 | True
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Themes/FluentTheme.axaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Themes/FluentTheme.axaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia.Controls;
3 | using Avalonia.Markup.Xaml;
4 | using Avalonia.Styling;
5 |
6 |
7 | namespace Egorozh.ColorPicker.Dialog;
8 |
9 |
10 | public class FluentTheme : Styles, IResourceNode
11 | {
12 | public FluentTheme(IServiceProvider? sp = null)
13 | {
14 | AvaloniaXamlLoader.Load(sp, this);
15 | }
16 | }
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Themes/SimpleTheme.axaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia.Dialog/Themes/SimpleTheme.axaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Avalonia.Controls;
3 | using Avalonia.Markup.Xaml;
4 | using Avalonia.Styling;
5 |
6 | namespace Egorozh.ColorPicker.Dialog;
7 |
8 | public class SimpleTheme : Styles, IResourceNode
9 | {
10 | public SimpleTheme(IServiceProvider? sp = null)
11 | {
12 | AvaloniaXamlLoader.Load(sp, this);
13 | }
14 | }
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia/ColorPickerControl.cs:
--------------------------------------------------------------------------------
1 | namespace Egorozh.ColorPicker;
2 |
3 | using Avalonia.Media;
4 |
5 | public class ColorPickerControl : TemplatedControl
6 | {
7 | #region Private Fields
8 |
9 | private readonly IColorManager _manager = new ColorManager();
10 | private bool _lock;
11 |
12 | #endregion
13 |
14 | #region Dependency Properties
15 |
16 | public static readonly StyledProperty LoadPaletteHandlerProperty =
17 | AvaloniaProperty.Register(nameof(LoadPaletteHandler));
18 |
19 | public static readonly StyledProperty SavePaletteHandlerProperty =
20 | AvaloniaProperty.Register(nameof(SavePaletteHandler));
21 |
22 | public static readonly StyledProperty GetColorHandlerProperty =
23 | AvaloniaProperty.Register(nameof(GetColorHandler));
24 |
25 | public static readonly StyledProperty> ColorsProperty =
26 | AvaloniaProperty.Register>(nameof(Colors));
27 |
28 | public static readonly StyledProperty ColorProperty =
29 | AvaloniaProperty.Register(nameof(Color));
30 |
31 | #endregion
32 |
33 | #region Public Properties
34 |
35 | public LoadPaletteHandlerAsync? LoadPaletteHandler
36 | {
37 | get => GetValue(LoadPaletteHandlerProperty);
38 | set => SetValue(LoadPaletteHandlerProperty, value);
39 | }
40 |
41 | public SavePaletteHandler? SavePaletteHandler
42 | {
43 | get => GetValue(SavePaletteHandlerProperty);
44 | set => SetValue(SavePaletteHandlerProperty, value);
45 | }
46 |
47 | public GetColorHandler? GetColorHandler
48 | {
49 | get => GetValue(GetColorHandlerProperty);
50 | set => SetValue(GetColorHandlerProperty, value);
51 | }
52 |
53 | public Color Color
54 | {
55 | get => GetValue(ColorProperty);
56 | set => SetValue(ColorProperty, value);
57 | }
58 |
59 | public IEnumerable Colors
60 | {
61 | get => GetValue(ColorsProperty);
62 | set => SetValue(ColorsProperty, value);
63 | }
64 |
65 | #endregion
66 |
67 | #region Protected Methods
68 |
69 | protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
70 | {
71 | base.OnApplyTemplate(e);
72 |
73 | _manager.ColorChanged += Manager_ColorChanged;
74 |
75 | var colorWheel = e.NameScope.Find("PART_ColorWheel");
76 | var colorPreview = e.NameScope.Find("PART_ColorPreview");
77 | var alphaSlider = e.NameScope.Find("PART_AlphaSlider");
78 | var valuesSlider = e.NameScope.Find("PART_ValueSlider");
79 | var colorEditor = e.NameScope.Find("PART_ColorEditor");
80 | var colorPalette = e.NameScope.Find("PART_ColorPalette");
81 |
82 | _manager.AddClient(colorWheel, colorPreview, alphaSlider,
83 | valuesSlider, colorEditor, colorPalette);
84 | }
85 |
86 |
87 | protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
88 | {
89 | base.OnPropertyChanged(change);
90 |
91 | if (change.Property == ColorProperty)
92 | {
93 | ColorChanged(this.Color);
94 | }
95 | }
96 |
97 |
98 | #endregion
99 |
100 | #region Private Methods
101 |
102 | private void Manager_ColorChanged(System.Drawing.Color color)
103 | {
104 | _lock = true;
105 |
106 | Color = color.ToColor();
107 |
108 | _lock = false;
109 | }
110 |
111 | private void ColorChanged(Color color)
112 | {
113 | if (_lock)
114 | return;
115 |
116 | _manager.ColorChanged -= Manager_ColorChanged;
117 |
118 | _manager.CurrentColor = color.ToColor();
119 |
120 | _manager.ColorChanged += Manager_ColorChanged;
121 | }
122 |
123 | #endregion
124 | }
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia/Controls/ColorEditor.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 |
3 | namespace Egorozh.ColorPicker;
4 |
5 | public class ColorEditor : TemplatedControl, IStyleable, IColorClient
6 | {
7 | #region Private Fields
8 |
9 | private IColorManager? _manager;
10 |
11 | private ListBox _modeComboBox;
12 |
13 | private RgbaColorSlider _rSlider;
14 | private RgbaColorNumericUpDown _rNumUpDown;
15 | private RgbaColorSlider _gSlider;
16 | private RgbaColorNumericUpDown _gNumUpDown;
17 | private RgbaColorSlider _bSlider;
18 | private RgbaColorNumericUpDown _bNumUpDown;
19 |
20 | private HueColorSlider _hSlider;
21 | private HueColorNumUpDown _hNumUpDown;
22 | private SaturationColorSlider _sSlider;
23 | private ValueColorSlider _vSlider;
24 | private ValueColorNumUpDown _vNumUpDown;
25 | private SaturationColorNumUpDown _sNumUpDown;
26 |
27 | #endregion
28 |
29 | #region IStyleable
30 |
31 | Type IStyleable.StyleKey => typeof(ColorEditor);
32 |
33 | #endregion
34 |
35 | #region Public Methods
36 |
37 | public void ColorUpdated(Color color, IColorClient client)
38 | {
39 | }
40 |
41 | public void Init(IColorManager colorManager)
42 | {
43 | _manager = colorManager;
44 | }
45 |
46 | #endregion
47 |
48 | #region Protected Methods
49 |
50 | protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
51 | {
52 | base.OnApplyTemplate(e);
53 |
54 | var hex = e.NameScope.Find("PART_HexComboBox");
55 | _modeComboBox = e.NameScope.Find("PART_ModeComboBox");
56 |
57 | var alphaSlider = e.NameScope.Find("PART_AlphaSlider");
58 | var alphaNumUpDown = e.NameScope.Find("PART_AlphaNumUpDown");
59 |
60 | _rSlider = e.NameScope.Find("PART_RSlider");
61 | _rNumUpDown = e.NameScope.Find("PART_RNumUpDown");
62 |
63 | _gSlider = e.NameScope.Find("PART_GSlider");
64 | _gNumUpDown = e.NameScope.Find("PART_GNumUpDown");
65 |
66 | _bSlider = e.NameScope.Find("PART_BSlider");
67 | _bNumUpDown = e.NameScope.Find("PART_BNumUpDown");
68 |
69 | _hSlider = e.NameScope.Find("PART_HSlider");
70 | _hNumUpDown = e.NameScope.Find("PART_HNumUpDown");
71 |
72 | _sSlider = e.NameScope.Find("PART_SSlider");
73 | _sNumUpDown = e.NameScope.Find("PART_SNumUpDown");
74 |
75 | _vSlider = e.NameScope.Find("PART_VSlider");
76 | _vNumUpDown = e.NameScope.Find("PART_VNumUpDown");
77 |
78 | _manager?.AddClient(alphaSlider, alphaNumUpDown, hex,
79 | _rSlider,
80 | _rNumUpDown,
81 | _gSlider,
82 | _gNumUpDown,
83 | _bSlider,
84 | _bNumUpDown,
85 | _hSlider,
86 | _hNumUpDown,
87 | _sSlider,
88 | _sNumUpDown,
89 | _vSlider,
90 | _vNumUpDown);
91 |
92 |
93 | _modeComboBox.SelectionChanged += ModeChanged;
94 | _modeComboBox.SelectedIndex = 0;
95 | }
96 |
97 | #endregion
98 |
99 | #region Private Methods
100 |
101 | private void ModeChanged(object? sender, SelectionChangedEventArgs e)
102 | {
103 | if (e.AddedItems.Count < 1)
104 | return;
105 |
106 | if (e.AddedItems[0] is ListBoxItem item)
107 | {
108 | CollapseClients();
109 |
110 | var mode = item.Content as string;
111 |
112 | switch (mode)
113 | {
114 | case "RGB":
115 |
116 | SetRgbVisible(true);
117 |
118 | break;
119 | case "HSV":
120 |
121 | SetHsvVisible(true);
122 |
123 | break;
124 | }
125 | }
126 | }
127 |
128 | private void CollapseClients()
129 | {
130 | SetRgbVisible(false);
131 | SetHsvVisible(false);
132 | }
133 |
134 | private void SetRgbVisible(bool isVisible)
135 | {
136 | _rSlider.IsVisible = isVisible;
137 | _rNumUpDown.IsVisible = isVisible;
138 |
139 | _gSlider.IsVisible = isVisible;
140 | _gNumUpDown.IsVisible = isVisible;
141 |
142 | _bSlider.IsVisible = isVisible;
143 | _bNumUpDown.IsVisible = isVisible;
144 | }
145 |
146 | private void SetHsvVisible(bool isVisible)
147 | {
148 | _hSlider.IsVisible = isVisible;
149 | _hNumUpDown.IsVisible = isVisible;
150 |
151 | _sSlider.IsVisible = isVisible;
152 | _sNumUpDown.IsVisible = isVisible;
153 |
154 | _vSlider.IsVisible = isVisible;
155 | _vNumUpDown.IsVisible = isVisible;
156 | }
157 |
158 | #endregion
159 | }
--------------------------------------------------------------------------------
/src/AvaloniaUI/Egorozh.ColorPicker.Avalonia/Controls/ColorHexComboBox.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 | using TextCopy;
3 |
4 | namespace Egorozh.ColorPicker;
5 |
6 | public class ColorHexComboBox : ComboBox, IStyleable, IColorClient
7 | {
8 | #region Private Fields
9 |
10 | private IColorManager _manager;
11 |
12 | #endregion
13 |
14 | #region IStyleable
15 |
16 | Type IStyleable.StyleKey => typeof(ColorHexComboBox);
17 |
18 | #endregion
19 |
20 | #region Public Methods
21 |
22 | public void ColorUpdated(Color color, IColorClient client)
23 | {
24 | SetSelectedItemInHex(color);
25 | }
26 |
27 | public void Init(IColorManager colorManager)
28 | {
29 | _manager = colorManager;
30 | }
31 |
32 | #endregion
33 |
34 | #region Protected Methods
35 |
36 | protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
37 | {
38 | base.OnApplyTemplate(e);
39 |
40 | ItemsSource = HexComboBoxHelpers.GetNamedColors();
41 | SelectionChanged += Hex_SelectionChanged;
42 |
43 | var copyButton = e.NameScope.Find