├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Images
├── Sample1.png
└── Sample2.png
├── LICENSE
├── README.md
└── Sources
├── Samples
└── WpfColorPicker.Sample.CSharp
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
│ └── WpfColorPicker.Sample.csproj
├── WpfColorPicker.sln
└── WpfColorPicker
├── ColorPickerDialog.xaml
├── ColorPickerDialog.xaml.cs
├── Converter
└── ColorToSolidBrushConverter.cs
├── Core
└── ColorUtilities.cs
├── CustomControls
├── ColorPicker.cs
├── ColorPickerBox.cs
├── ColorThumb.cs
└── SpectrumSlider.cs
├── Enumeration.cs
├── GlobalStruct.cs
├── Properties
└── AssemblyInfo.cs
├── Themes
└── generic.xaml
├── WpfColorPicker.csproj
└── license.txt
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at derektremblay666@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Contributing...
2 |
--------------------------------------------------------------------------------
/Images/Sample1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbaye/WpfColorPicker/51a2025f07967706b4f420ffa3c6068ca83b57b8/Images/Sample1.png
--------------------------------------------------------------------------------
/Images/Sample2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbaye/WpfColorPicker/51a2025f07967706b4f420ffa3c6068ca83b57b8/Images/Sample2.png
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Derek Tremblay
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 | # Wpf ColorPicker controls
2 |
3 | ## 🎯 ATTENTION : BUILD WITH VISUAL STUDIO 2019 v16.3.7+
4 |
5 | Wpf ColorPicker is a set of customs usercontrol that can take color in your app.
6 |
7 | Forked base from an old 2006 Microsoft sample project. I have adapted the code to be more actual and I will add somes other new colors picker from me.
8 |
9 | I will add localisation, new features and controls like colorpicker combobox...
10 |
11 | ### 🖼 Screenshots
12 |
13 | Principal control form Microsoft 2006 Sample (I want to enchanced it soon)
14 |
15 |
16 |
17 | New ColorPickerBox: Work in progress control...
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/App.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace WpfColorPicker.Sample.CSharp.NET451
10 | {
11 | ///
12 | /// Logique d'interaction pour App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // MIT - 2019
3 | // Author : Derek Tremblay (derektremblay666@gmail.com)
4 | //////////////////////////////////////////////
5 |
6 | using System.Windows;
7 |
8 | namespace WpfColorPicker.Sample.CSharp.NET451
9 | {
10 | ///
11 | /// Sample of color picker controls collection
12 | ///
13 | public partial class MainWindow : Window
14 | {
15 | public MainWindow() => InitializeComponent();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using System.Windows;
3 |
4 | // L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
5 | // aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
6 | // COM, affectez la valeur True à l'attribut ComVisible sur ce type.
7 | [assembly: ComVisible(false)]
8 |
9 |
10 | [assembly: ThemeInfo(
11 | ResourceDictionaryLocation.None, //où se trouvent les dictionnaires de ressources spécifiques à un thème
12 | //(utilisé si une ressource est introuvable dans la page,
13 | // ou dictionnaires de ressources de l'application)
14 | ResourceDictionaryLocation.SourceAssembly //où se trouve le dictionnaire de ressources générique
15 | //(utilisé si une ressource est introuvable dans la page,
16 | // dans l'application ou dans l'un des dictionnaires de ressources spécifiques à un thème)
17 | )]
18 |
19 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // Ce code a été généré par un outil.
4 | // Version du runtime :4.0.30319.42000
5 | //
6 | // Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
7 | // le code est régénéré.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WpfColorPicker.Sample.CSharp.NET451.Properties
12 | {
13 |
14 |
15 | ///
16 | /// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
17 | ///
18 | // Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder
19 | // à l'aide d'un outil, tel que ResGen ou Visual Studio.
20 | // Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
21 | // avec l'option /str ou régénérez votre projet VS.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WpfColorPicker.Sample.CSharp.NET451.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Remplace la propriété CurrentUICulture du thread actuel pour toutes
56 | /// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace WpfColorPicker.Sample.CSharp.NET451.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Sources/Samples/WpfColorPicker.Sample.CSharp/WpfColorPicker.Sample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | netcoreapp3.0;net45;net47
6 | true
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29509.3
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfColorPicker", "WpfColorPicker\WpfColorPicker.csproj", "{99E90579-62FC-4898-B168-24F7DBD3A34D}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfColorPicker.Sample", "Samples\WpfColorPicker.Sample.CSharp\WpfColorPicker.Sample.csproj", "{EB55D2E8-A2D7-4B61-953B-AB422AA62571}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {99E90579-62FC-4898-B168-24F7DBD3A34D}.Debug|Any CPU.ActiveCfg = Release|Any CPU
17 | {99E90579-62FC-4898-B168-24F7DBD3A34D}.Debug|Any CPU.Build.0 = Release|Any CPU
18 | {99E90579-62FC-4898-B168-24F7DBD3A34D}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {99E90579-62FC-4898-B168-24F7DBD3A34D}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {EB55D2E8-A2D7-4B61-953B-AB422AA62571}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {EB55D2E8-A2D7-4B61-953B-AB422AA62571}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {EB55D2E8-A2D7-4B61-953B-AB422AA62571}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {EB55D2E8-A2D7-4B61-953B-AB422AA62571}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {1ECD3ECC-0918-4FA2-9550-45DEAE4B2484}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/ColorPickerDialog.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
16 |
17 |
22 |
29 |
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/ColorPickerDialog.xaml.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // 2006 - Microsoft
3 | // https://blogs.msdn.microsoft.com/wpfsdk/2006/10/26/uncommon-dialogs-font-chooser-color-picker-dialogs/
4 | //
5 | // 2019 - Modified and adapted by Derek Tremblay (derektremblay666@gmail.com)
6 | //////////////////////////////////////////////
7 |
8 | using System.Windows;
9 | using System.Windows.Media;
10 |
11 | namespace WpfColorPicker
12 | {
13 | ///
14 | /// ColorPickerDialog used to pick colors
15 | ///
16 | public partial class ColorPickerDialog : Window
17 | {
18 | private Color _color = new Color();
19 | private Color _startingColor = new Color();
20 |
21 | public ColorPickerDialog() => InitializeComponent();
22 |
23 | private void OkButtonClicked(object sender, RoutedEventArgs e)
24 | {
25 | OKButton.IsEnabled = false;
26 | _color = cPicker.SelectedColor;
27 | DialogResult = true;
28 | Hide();
29 | }
30 |
31 | private void CancelButtonClicked(object sender, RoutedEventArgs e)
32 | {
33 | OKButton.IsEnabled = false;
34 | DialogResult = false;
35 | }
36 |
37 | private void OnSelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e)
38 | {
39 | if (e.NewValue == _color) return;
40 |
41 | OKButton.IsEnabled = true;
42 | }
43 |
44 | protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
45 | {
46 | OKButton.IsEnabled = false;
47 | base.OnClosing(e);
48 | }
49 |
50 | public Color SelectedColor => _color;
51 |
52 | public Color StartingColor
53 | {
54 | get => _startingColor;
55 | set
56 | {
57 | cPicker.SelectedColor = value;
58 | OKButton.IsEnabled = false;
59 | }
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/Converter/ColorToSolidBrushConverter.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // MIT - 2019
3 | // Author : Derek Tremblay (derektremblay666@gmail.com)
4 | //////////////////////////////////////////////
5 |
6 | using System;
7 | using System.Globalization;
8 | using System.Windows.Data;
9 | using System.Windows.Media;
10 |
11 | namespace WpfColorPicker.Converter
12 | {
13 | public class ColorToSolidBrushConverter : IValueConverter
14 | {
15 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
16 | new SolidColorBrush((Color)value);
17 |
18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
19 | {
20 | throw new NotImplementedException();
21 | //return value.ToString();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/Core/ColorUtilities.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // 2006 - Microsoft / Sample
3 | // https://blogs.msdn.microsoft.com/wpfsdk/2006/10/26/uncommon-dialogs-font-chooser-color-picker-dialogs/
4 | //
5 | // 2019 - Forked by Derek Tremblay (derektremblay666@gmail.com)
6 | //////////////////////////////////////////////
7 |
8 | using System;
9 | using System.Windows.Media;
10 | using System.Collections.Generic;
11 |
12 | namespace WpfColorPicker.Core
13 | {
14 | static class ColorUtilities
15 | {
16 | ///
17 | /// Converts an RGB color to an HSV color.
18 | ///
19 | public static HsvColor ConvertRgbToHsv(int r, int b, int g)
20 | {
21 | double delta, min;
22 | double h = 0, s, v;
23 |
24 | min = Math.Min(Math.Min(r, g), b);
25 | v = Math.Max(Math.Max(r, g), b);
26 | delta = v - min;
27 |
28 | s = v == 0.0 ? 0 : delta / v;
29 |
30 | if (s == 0)
31 | h = 0.0;
32 | else
33 | {
34 | if (r == v)
35 | h = (g - b) / delta;
36 | else if (g == v)
37 | h = 2 + (b - r) / delta;
38 | else if (b == v)
39 | h = 4 + (r - g) / delta;
40 |
41 | h *= 60;
42 | if (h < 0.0)
43 | h += 360;
44 | }
45 |
46 | HsvColor hsvColor = new HsvColor
47 | {
48 | H = h,
49 | S = s,
50 | V = v / 255
51 | };
52 |
53 | return hsvColor;
54 | }
55 |
56 | ///
57 | /// Converts an HSV color to an RGB color.
58 | ///
59 | public static Color ConvertHsvToRgb(double h, double s, double v)
60 | {
61 | double r, g, b;
62 |
63 | if (s == 0)
64 | r = g = b = v;
65 | else
66 | {
67 | int i;
68 | double f, p, q, t;
69 |
70 | h = h == 360 ? 0 : h / 60;
71 |
72 | i = (int)Math.Truncate(h);
73 | f = h - i;
74 |
75 | p = v * (1.0 - s);
76 | q = v * (1.0 - (s * f));
77 | t = v * (1.0 - (s * (1.0 - f)));
78 |
79 | switch (i)
80 | {
81 | case 0:
82 | r = v;
83 | g = t;
84 | b = p;
85 | break;
86 | case 1:
87 | r = q;
88 | g = v;
89 | b = p;
90 | break;
91 | case 2:
92 | r = p;
93 | g = v;
94 | b = t;
95 | break;
96 | case 3:
97 | r = p;
98 | g = q;
99 | b = v;
100 | break;
101 | case 4:
102 | r = t;
103 | g = p;
104 | b = v;
105 | break;
106 | default:
107 | r = v;
108 | g = p;
109 | b = q;
110 | break;
111 | }
112 | }
113 |
114 | return Color.FromArgb(255, (byte)(r * 255), (byte)(g * 255), (byte)(b * 255));
115 | }
116 |
117 | ///
118 | /// Generates a list of colors with hues ranging from 0 360 and a saturation and value of 1.
119 | ///
120 | public static List GenerateHsvSpectrum()
121 | {
122 | List colorsList = new List(8);
123 |
124 | for (int i = 0; i < 29; i++)
125 | colorsList.Add
126 | (
127 | ConvertHsvToRgb(i * 12, 1, 1)
128 | );
129 |
130 | colorsList.Add(ConvertHsvToRgb(0, 1, 1));
131 |
132 | return colorsList;
133 | }
134 | }
135 | }
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/CustomControls/ColorPicker.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // 2006 - Microsoft / Sample
3 | // https://blogs.msdn.microsoft.com/wpfsdk/2006/10/26/uncommon-dialogs-font-chooser-color-picker-dialogs/
4 | //
5 | // 2019 - Forked by Derek Tremblay (derektremblay666@gmail.com)
6 | //////////////////////////////////////////////
7 |
8 | using System;
9 | using System.Windows;
10 | using System.Windows.Media;
11 | using System.Windows.Shapes;
12 | using System.Windows.Controls;
13 | using System.Windows.Input;
14 | using WpfColorPicker.Core;
15 |
16 | namespace WpfColorPicker.CustomControls
17 | {
18 | ///
19 | /// An HSB (hue, saturation, brightness) based color picker.
20 | ///
21 | public class ColorPicker : Control
22 | {
23 | #region Global variables
24 | private SpectrumSlider _ColorSlider;
25 | private FrameworkElement _ColorDetail;
26 | private Path _ColorMarker;
27 | private const string _ColorMarkerName = "PART_ColorMarker";
28 | private const string _ColorSliderName = "PART_ColorSlider";
29 | private const string _ColorDetailName = "PART_ColorDetail";
30 | private readonly TranslateTransform _markerTransform = new TranslateTransform();
31 | private Point? _ColorPosition;
32 | private Color _color;
33 | private bool _shouldFindPoint;
34 | private bool _templateApplied;
35 | private bool _isAlphaChange;
36 | #endregion
37 |
38 | static ColorPicker() =>
39 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorPicker),
40 | new FrameworkPropertyMetadata(typeof(ColorPicker)));
41 |
42 | public ColorPicker()
43 | {
44 | _templateApplied = false;
45 | _color = Colors.White;
46 | _shouldFindPoint = true;
47 |
48 | SetValue(AProperty, _color.A);
49 | SetValue(RProperty, _color.R);
50 | SetValue(GProperty, _color.G);
51 | SetValue(BProperty, _color.B);
52 | SetValue(SelectedColorProperty, _color);
53 | }
54 |
55 | #region Public Methods
56 |
57 | public override void OnApplyTemplate()
58 | {
59 | base.OnApplyTemplate();
60 | _ColorDetail = GetTemplateChild(_ColorDetailName) as FrameworkElement;
61 | _ColorMarker = GetTemplateChild(_ColorMarkerName) as Path;
62 | _ColorSlider = GetTemplateChild(_ColorSliderName) as SpectrumSlider;
63 | _ColorSlider.ValueChanged += new RoutedPropertyChangedEventHandler(BaseColorChanged);
64 | _ColorMarker.RenderTransform = _markerTransform;
65 | _ColorMarker.RenderTransformOrigin = new Point(0.5, 0.5);
66 | _ColorDetail.MouseLeftButtonDown += new MouseButtonEventHandler(OnMouseLeftButtonDown);
67 | _ColorDetail.PreviewMouseMove += new MouseEventHandler(OnMouseMove);
68 | _ColorDetail.SizeChanged += new SizeChangedEventHandler(ColorDetailSizeChanged);
69 |
70 | _templateApplied = true;
71 | _shouldFindPoint = true;
72 | _isAlphaChange = false;
73 |
74 | SelectedColor = _color;
75 | }
76 | #endregion
77 |
78 | #region Public Properties
79 |
80 | ///
81 | /// Gets or sets the selected color.
82 | ///
83 | public Color SelectedColor
84 | {
85 | get => (Color)GetValue(SelectedColorProperty);
86 | set
87 | {
88 | SetValue(SelectedColorProperty, _color);
89 | SetColor((Color)value);
90 | }
91 | }
92 |
93 | #region RGB Properties
94 | ///
95 | /// Gets or sets the ARGB alpha value of the selected color.
96 | ///
97 | public byte A
98 | {
99 | get => (byte)GetValue(AProperty);
100 | set => SetValue(AProperty, value);
101 | }
102 |
103 | ///
104 | /// Gets or sets the ARGB red value of the selected color.
105 | ///
106 | public byte R
107 | {
108 | get => (byte)GetValue(RProperty);
109 | set => SetValue(RProperty, value);
110 | }
111 |
112 | ///
113 | /// Gets or sets the ARGB green value of the selected color.
114 | ///
115 | public byte G
116 | {
117 | get => (byte)GetValue(GProperty);
118 | set => SetValue(GProperty, value);
119 | }
120 |
121 | ///
122 | /// Gets or sets the ARGB blue value of the selected color.
123 | ///
124 | public byte B
125 | {
126 | get => (byte)GetValue(BProperty);
127 | set => SetValue(BProperty, value);
128 | }
129 | #endregion RGB Properties
130 |
131 | #region ScRGB Properties
132 |
133 | ///
134 | /// Gets or sets the ScRGB alpha value of the selected color.
135 | ///
136 | public double ScA
137 | {
138 | get => (double)GetValue(ScAProperty);
139 | set => SetValue(ScAProperty, value);
140 | }
141 |
142 | ///
143 | /// Gets or sets the ScRGB red value of the selected color.
144 | ///
145 | public double ScR
146 | {
147 | get => (double)GetValue(ScRProperty);
148 | set => SetValue(RProperty, value);
149 | }
150 |
151 | ///
152 | /// Gets or sets the ScRGB green value of the selected color.
153 | ///
154 | public double ScG
155 | {
156 | get => (double)GetValue(ScGProperty);
157 | set => SetValue(GProperty, value);
158 | }
159 |
160 | ///
161 | /// Gets or sets the ScRGB blue value of the selected color.
162 | ///
163 | public double ScB
164 | {
165 | get => (double)GetValue(BProperty);
166 | set => SetValue(BProperty, value);
167 | }
168 | #endregion ScRGB Properties
169 |
170 | ///
171 | /// Gets or sets the the selected color in hexadecimal notation.
172 | ///
173 | public string HexadecimalString
174 | {
175 | get => (string)GetValue(HexadecimalStringProperty);
176 | set => SetValue(HexadecimalStringProperty, value);
177 | }
178 | #endregion
179 |
180 | #region Public Events
181 |
182 | public event RoutedPropertyChangedEventHandler SelectedColorChanged
183 | {
184 | add
185 | {
186 | AddHandler(SelectedColorChangedEvent, value);
187 | }
188 |
189 | remove
190 | {
191 | RemoveHandler(SelectedColorChangedEvent, value);
192 | }
193 | }
194 |
195 | #endregion
196 |
197 | #region Dependency Property Fields
198 | public static readonly DependencyProperty SelectedColorProperty =
199 | DependencyProperty.Register (nameof(SelectedColor), typeof(Color), typeof(ColorPicker),
200 | new PropertyMetadata(Colors.Transparent, new PropertyChangedCallback(SelectedColor_changed)));
201 |
202 | public static readonly DependencyProperty ScAProperty =
203 | DependencyProperty.Register(nameof(ScA), typeof(float), typeof(ColorPicker),
204 | new PropertyMetadata((float)1, new PropertyChangedCallback(ScAChanged)));
205 |
206 | public static readonly DependencyProperty ScRProperty =
207 | DependencyProperty.Register(nameof(ScR), typeof(float), typeof(ColorPicker),
208 | new PropertyMetadata((float)1, new PropertyChangedCallback(ScRChanged)));
209 |
210 | public static readonly DependencyProperty ScGProperty =
211 | DependencyProperty.Register(nameof(ScG), typeof(float), typeof(ColorPicker),
212 | new PropertyMetadata((float)1, new PropertyChangedCallback(ScGChanged)));
213 |
214 | public static readonly DependencyProperty ScBProperty =
215 | DependencyProperty.Register(nameof(ScB), typeof(float), typeof(ColorPicker),
216 | new PropertyMetadata((float)1, new PropertyChangedCallback(ScBChanged)));
217 |
218 | public static readonly DependencyProperty AProperty =
219 | DependencyProperty.Register(nameof(A), typeof(byte), typeof(ColorPicker),
220 | new PropertyMetadata((byte)255, new PropertyChangedCallback(AChanged)));
221 |
222 | public static readonly DependencyProperty RProperty =
223 | DependencyProperty.Register(nameof(R), typeof(byte), typeof(ColorPicker),
224 | new PropertyMetadata((byte)255, new PropertyChangedCallback(RChanged)));
225 |
226 | public static readonly DependencyProperty GProperty =
227 | DependencyProperty.Register(nameof(G), typeof(byte), typeof(ColorPicker),
228 | new PropertyMetadata((byte)255, new PropertyChangedCallback(GChanged)));
229 |
230 | public static readonly DependencyProperty BProperty =
231 | DependencyProperty.Register(nameof(B), typeof(byte), typeof(ColorPicker),
232 | new PropertyMetadata((byte)255, new PropertyChangedCallback(BChanged)));
233 |
234 | public static readonly DependencyProperty HexadecimalStringProperty =
235 | DependencyProperty.Register(nameof(HexadecimalString), typeof(string), typeof(ColorPicker),
236 | new PropertyMetadata("#FFFFFFFF", new PropertyChangedCallback(HexadecimalStringChanged)));
237 | #endregion
238 |
239 | #region RoutedEvent Fields
240 |
241 | public static readonly RoutedEvent SelectedColorChangedEvent = EventManager.RegisterRoutedEvent(
242 | nameof(SelectedColorChanged), RoutingStrategy.Bubble,
243 | typeof(RoutedPropertyChangedEventHandler), typeof(ColorPicker));
244 | #endregion
245 |
246 | #region Property Changed Callbacks
247 |
248 | private static void AChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
249 | {
250 | ColorPicker c = (ColorPicker)d;
251 | c.OnAChanged((byte)e.NewValue);
252 | }
253 |
254 | protected virtual void OnAChanged(byte newValue)
255 | {
256 | _color.A = newValue;
257 | SetValue(ScAProperty, _color.ScA);
258 | SetValue(SelectedColorProperty, _color);
259 | }
260 |
261 | private static void RChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
262 | {
263 | ColorPicker c = (ColorPicker)d;
264 | c.OnRChanged((byte)e.NewValue);
265 | }
266 |
267 | protected virtual void OnRChanged(byte newValue)
268 | {
269 | _color.R = newValue;
270 | SetValue(ScRProperty, _color.ScR);
271 | SetValue(SelectedColorProperty, _color);
272 | }
273 |
274 | private static void GChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
275 | {
276 | ColorPicker c = (ColorPicker)d;
277 | c.OnGChanged((byte)e.NewValue);
278 | }
279 |
280 | protected virtual void OnGChanged(byte newValue)
281 | {
282 | _color.G = newValue;
283 | SetValue(ScGProperty, _color.ScG);
284 | SetValue(SelectedColorProperty, _color);
285 | }
286 |
287 | private static void BChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
288 | {
289 | ColorPicker c = (ColorPicker)d;
290 | c.OnBChanged((byte)e.NewValue);
291 | }
292 |
293 | protected virtual void OnBChanged(byte newValue)
294 | {
295 | _color.B = newValue;
296 | SetValue(ScBProperty, _color.ScB);
297 | SetValue(SelectedColorProperty, _color);
298 | }
299 |
300 | private static void ScAChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
301 | {
302 | ColorPicker c = (ColorPicker)d;
303 | c.OnScAChanged((float)e.NewValue);
304 | }
305 |
306 | protected virtual void OnScAChanged(float newValue)
307 | {
308 | _isAlphaChange = true;
309 | if (_shouldFindPoint)
310 | {
311 | _color.ScA = newValue;
312 | SetValue(AProperty, _color.A);
313 | SetValue(SelectedColorProperty, _color);
314 | SetValue(HexadecimalStringProperty, _color.ToString());
315 | }
316 | _isAlphaChange = false;
317 | }
318 |
319 | private static void ScRChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
320 | {
321 | ColorPicker c = (ColorPicker)d;
322 | c.OnScRChanged((float)e.NewValue);
323 | }
324 |
325 | protected virtual void OnScRChanged(float newValue)
326 | {
327 | if (!_shouldFindPoint) return;
328 |
329 | _color.ScR = newValue;
330 | SetValue(RProperty, _color.R);
331 | SetValue(SelectedColorProperty, _color);
332 | SetValue(HexadecimalStringProperty, _color.ToString());
333 | }
334 |
335 | private static void ScGChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
336 | {
337 | ColorPicker c = (ColorPicker)d;
338 | c.OnScGChanged((float)e.NewValue);
339 | }
340 |
341 | protected virtual void OnScGChanged(float newValue)
342 | {
343 | if (!_shouldFindPoint) return;
344 |
345 | _color.ScG = newValue;
346 | SetValue(GProperty, _color.G);
347 | SetValue(SelectedColorProperty, _color);
348 | SetValue(HexadecimalStringProperty, _color.ToString());
349 | }
350 |
351 | private static void ScBChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
352 | {
353 | ColorPicker c = (ColorPicker)d;
354 | c.OnScBChanged((float)e.NewValue);
355 | }
356 |
357 | protected virtual void OnScBChanged(float newValue)
358 | {
359 | if (!_shouldFindPoint) return;
360 |
361 | _color.ScB = newValue;
362 | SetValue(BProperty, _color.B);
363 | SetValue(SelectedColorProperty, _color);
364 | SetValue(HexadecimalStringProperty, _color.ToString());
365 | }
366 |
367 | private static void HexadecimalStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
368 | {
369 | ColorPicker c = (ColorPicker)d;
370 | c.OnHexadecimalStringChanged((string)e.OldValue, (string)e.NewValue);
371 | }
372 |
373 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "")]
374 | protected virtual void OnHexadecimalStringChanged(string oldValue, string newValue)
375 | {
376 | try
377 | {
378 | if (_shouldFindPoint)
379 | _color = (Color)ColorConverter.ConvertFromString(newValue);
380 |
381 | SetValue(AProperty, _color.A);
382 | SetValue(RProperty, _color.R);
383 | SetValue(GProperty, _color.G);
384 | SetValue(BProperty, _color.B);
385 |
386 | if (_shouldFindPoint && !_isAlphaChange && _templateApplied)
387 | UpdateMarkerPosition(_color);
388 | }
389 | catch (FormatException)
390 | {
391 | SetValue(HexadecimalStringProperty, oldValue);
392 | }
393 | }
394 |
395 | private static void SelectedColor_changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
396 | {
397 | ColorPicker cPicker = (ColorPicker)d;
398 | cPicker.OnSelectedColorChanged((Color)e.OldValue, (Color)e.NewValue);
399 | }
400 |
401 | protected virtual void OnSelectedColorChanged(Color oldColor, Color newColor)
402 | {
403 | RoutedPropertyChangedEventArgs newEventArgs =
404 | new RoutedPropertyChangedEventArgs(oldColor, newColor)
405 | {
406 | RoutedEvent = SelectedColorChangedEvent
407 | };
408 |
409 | RaiseEvent(newEventArgs);
410 | }
411 |
412 | #endregion
413 |
414 | #region Template Part Event Handlers
415 | protected override void OnTemplateChanged(ControlTemplate oldTemplate, ControlTemplate newTemplate)
416 | {
417 | _templateApplied = false;
418 | if (oldTemplate != null)
419 | {
420 | _ColorSlider.ValueChanged -= new RoutedPropertyChangedEventHandler(BaseColorChanged);
421 | _ColorDetail.MouseLeftButtonDown -= new MouseButtonEventHandler(OnMouseLeftButtonDown);
422 | _ColorDetail.PreviewMouseMove -= new MouseEventHandler(OnMouseMove);
423 | _ColorDetail.SizeChanged -= new SizeChangedEventHandler(ColorDetailSizeChanged);
424 | _ColorDetail = null;
425 | _ColorMarker = null;
426 | _ColorSlider = null;
427 | }
428 | base.OnTemplateChanged(oldTemplate, newTemplate);
429 |
430 | }
431 |
432 | private void BaseColorChanged(object sender, RoutedPropertyChangedEventArgs e)
433 | {
434 | if (_ColorPosition != null)
435 | DetermineColor((Point)_ColorPosition);
436 | }
437 |
438 | private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
439 | {
440 | Point p = e.GetPosition(_ColorDetail);
441 | UpdateMarkerPosition(p);
442 | }
443 |
444 | private void OnMouseMove(object sender, MouseEventArgs e)
445 | {
446 | if (e.LeftButton != MouseButtonState.Pressed) return;
447 |
448 | Point p = e.GetPosition(_ColorDetail);
449 | UpdateMarkerPosition(p);
450 | Mouse.Synchronize();
451 | }
452 |
453 | private void ColorDetailSizeChanged(object sender, SizeChangedEventArgs args)
454 | {
455 | if (args.PreviousSize != Size.Empty &&
456 | args.PreviousSize.Width != 0 &&
457 | args.PreviousSize.Height != 0)
458 | {
459 | var widthDifference = args.NewSize.Width / args.PreviousSize.Width;
460 | var heightDifference = args.NewSize.Height / args.PreviousSize.Height;
461 | _markerTransform.X *= widthDifference;
462 | _markerTransform.Y *= heightDifference;
463 | }
464 | else if (_ColorPosition != null)
465 | {
466 | _markerTransform.X = ((Point)_ColorPosition).X * args.NewSize.Width;
467 | _markerTransform.Y = ((Point)_ColorPosition).Y * args.NewSize.Height;
468 | }
469 | }
470 | #endregion
471 |
472 | #region Color Resolution Helpers
473 |
474 | private void SetColor(Color theColor)
475 | {
476 | _color = theColor;
477 |
478 | if (!_templateApplied) return;
479 |
480 | SetValue(AProperty, _color.A);
481 | SetValue(RProperty, _color.R);
482 | SetValue(GProperty, _color.G);
483 | SetValue(BProperty, _color.B);
484 | UpdateMarkerPosition(theColor);
485 | }
486 |
487 | private void UpdateMarkerPosition(Point p)
488 | {
489 | _markerTransform.X = p.X;
490 | _markerTransform.Y = p.Y;
491 | p.X /= _ColorDetail.ActualWidth;
492 | p.Y /= _ColorDetail.ActualHeight;
493 | _ColorPosition = p;
494 | DetermineColor(p);
495 | }
496 |
497 | private void UpdateMarkerPosition(Color theColor)
498 | {
499 | _ColorPosition = null;
500 |
501 | HsvColor hsv = ColorUtilities.ConvertRgbToHsv(theColor.R, theColor.G, theColor.B);
502 |
503 | _ColorSlider.Value = hsv.H;
504 |
505 | Point p = new Point(hsv.S, 1 - hsv.V);
506 |
507 | _ColorPosition = p;
508 | p.X *= _ColorDetail.ActualWidth;
509 | p.Y *= _ColorDetail.ActualHeight;
510 | _markerTransform.X = p.X;
511 | _markerTransform.Y = p.Y;
512 | }
513 |
514 | private void DetermineColor(Point p)
515 | {
516 | HsvColor hsv = new HsvColor(360 - _ColorSlider.Value, 1, 1)
517 | {
518 | S = p.X,
519 | V = 1 - p.Y
520 | };
521 |
522 | _color = ColorUtilities.ConvertHsvToRgb(hsv.H, hsv.S, hsv.V);
523 | _shouldFindPoint = false;
524 | _color.ScA = (float)GetValue(ScAProperty);
525 | SetValue(HexadecimalStringProperty, _color.ToString());
526 | _shouldFindPoint = true;
527 | }
528 |
529 | #endregion
530 | }
531 | }
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/CustomControls/ColorPickerBox.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // MIT - 2019
3 | // Author : Derek Tremblay (derektremblay666@gmail.com)
4 | //////////////////////////////////////////////
5 |
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Windows;
9 | using System.Windows.Controls;
10 | using System.Windows.Media;
11 |
12 | namespace WpfColorPicker.CustomControls
13 | {
14 | public class ColorPickerBox : ComboBox
15 | {
16 | static ColorPickerBox() =>
17 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorPickerBox),
18 | new FrameworkPropertyMetadata(typeof(ColorPickerBox)));
19 |
20 | public ColorPickerBox()
21 | {
22 | ItemsSource = GetAllColors();
23 |
24 | DataContext = this;
25 | }
26 |
27 | private IEnumerable> GetAllColors() =>
28 | typeof(Colors)
29 | .GetProperties()
30 | .Where(prop => typeof(Color).IsAssignableFrom(prop.PropertyType))
31 | .Select(prop => new KeyValuePair(prop.Name, (Color)prop.GetValue(null)));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/CustomControls/ColorThumb.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // 2006 - Microsoft / Sample
3 | // https://blogs.msdn.microsoft.com/wpfsdk/2006/10/26/uncommon-dialogs-font-chooser-color-picker-dialogs/
4 | //
5 | // 2019 - Forked by Derek Tremblay (derektremblay666@gmail.com)
6 | //////////////////////////////////////////////
7 |
8 | using System.Windows;
9 | using System.Windows.Media;
10 |
11 | namespace WpfColorPicker.CustomControls
12 | {
13 | public class ColorThumb : System.Windows.Controls.Primitives.Thumb
14 | {
15 | static ColorThumb() =>
16 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorThumb),
17 | new FrameworkPropertyMetadata(typeof(ColorThumb)));
18 |
19 | public static readonly DependencyProperty ThumbColorProperty =
20 | DependencyProperty.Register(nameof(ThumbColor), typeof(Color), typeof(ColorThumb),
21 | new FrameworkPropertyMetadata(Colors.Transparent));
22 |
23 | public static readonly DependencyProperty PointerOutlineThicknessProperty =
24 | DependencyProperty.Register(nameof(PointerOutlineThickness), typeof(double), typeof(ColorThumb),
25 | new FrameworkPropertyMetadata(1.0));
26 |
27 | public static readonly DependencyProperty PointerOutlineBrushProperty =
28 | DependencyProperty.Register("PointerOutlineBrush", typeof(Brush), typeof(ColorThumb),
29 | new FrameworkPropertyMetadata(null));
30 |
31 | public Color ThumbColor
32 | {
33 | get => (Color)GetValue(ThumbColorProperty);
34 | set => SetValue(ThumbColorProperty, value);
35 | }
36 |
37 | public double PointerOutlineThickness
38 | {
39 | get => (double)GetValue(PointerOutlineThicknessProperty);
40 | set => SetValue(PointerOutlineThicknessProperty, value);
41 | }
42 |
43 | public Brush PointerOutlineBrush
44 | {
45 | get => (Brush)GetValue(PointerOutlineBrushProperty);
46 | set => SetValue(PointerOutlineBrushProperty, value);
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/CustomControls/SpectrumSlider.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // 2006 - Microsoft / Sample
3 | // https://blogs.msdn.microsoft.com/wpfsdk/2006/10/26/uncommon-dialogs-font-chooser-color-picker-dialogs/
4 | //
5 | // 2019 - Forked by Derek Tremblay (derektremblay666@gmail.com)
6 | //////////////////////////////////////////////
7 |
8 | using System;
9 | using System.Windows;
10 | using System.Windows.Media;
11 | using System.Windows.Shapes;
12 | using System.Windows.Controls;
13 | using WpfColorPicker.Core;
14 |
15 | namespace WpfColorPicker.CustomControls
16 | {
17 | public class SpectrumSlider : Slider
18 | {
19 | #region Private Fields
20 | private const string _spectrumDisplayName = "PART_SpectrumDisplay";
21 | private Rectangle _spectrumDisplay;
22 | private LinearGradientBrush _pickerBrush;
23 | #endregion
24 |
25 | static SpectrumSlider() =>
26 | DefaultStyleKeyProperty.OverrideMetadata(typeof(SpectrumSlider),
27 | new FrameworkPropertyMetadata(typeof(SpectrumSlider)));
28 |
29 | #region Public Properties
30 | public Color SelectedColor
31 | {
32 | get => (Color)GetValue(SelectedColorProperty);
33 | set => SetValue(SelectedColorProperty, value);
34 | }
35 | #endregion
36 |
37 | #region Dependency Property Fields
38 | public static readonly DependencyProperty SelectedColorProperty =
39 | DependencyProperty.Register(nameof(SelectedColor), typeof(Color), typeof(SpectrumSlider),
40 | new PropertyMetadata(Colors.Transparent));
41 | #endregion
42 |
43 | #region Public Methods
44 |
45 | public override void OnApplyTemplate()
46 | {
47 | base.OnApplyTemplate();
48 | _spectrumDisplay = GetTemplateChild(_spectrumDisplayName) as Rectangle;
49 | UpdateColorSpectrum();
50 | OnValueChanged(Double.NaN, Value);
51 | }
52 | #endregion
53 |
54 | #region Protected Methods
55 | protected override void OnValueChanged(double oldValue, double newValue)
56 | {
57 | base.OnValueChanged(oldValue, newValue);
58 | var theColor = ColorUtilities.ConvertHsvToRgb(360 - newValue, 1, 1);
59 | SetValue(SelectedColorProperty, theColor);
60 | }
61 | #endregion
62 |
63 | #region Private Methods
64 |
65 | private void UpdateColorSpectrum()
66 | {
67 | if (_spectrumDisplay == null) return;
68 | CreateSpectrum();
69 | }
70 |
71 | private void CreateSpectrum()
72 | {
73 | _pickerBrush = new LinearGradientBrush
74 | {
75 | StartPoint = new Point(0.5, 0),
76 | EndPoint = new Point(0.5, 1),
77 | ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation
78 | };
79 |
80 | var colorsList = ColorUtilities.GenerateHsvSpectrum();
81 | var stopIncrement = (double)1 / colorsList.Count;
82 |
83 | int i;
84 | for (i = 0; i < colorsList.Count; i++)
85 | _pickerBrush.GradientStops.Add(new GradientStop(colorsList[i], i * stopIncrement));
86 |
87 | _pickerBrush.GradientStops[i - 1].Offset = 1.0;
88 | _spectrumDisplay.Fill = _pickerBrush;
89 | }
90 | #endregion
91 | }
92 | }
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/Enumeration.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace WpfColorPicker
8 | {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/GlobalStruct.cs:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////
2 | // 2006 - Microsoft / Sample
3 | // https://blogs.msdn.microsoft.com/wpfsdk/2006/10/26/uncommon-dialogs-font-chooser-color-picker-dialogs/
4 | //
5 | // 2019 - Forked by Derek Tremblay (derektremblay666@gmail.com)
6 | //////////////////////////////////////////////
7 |
8 | namespace WpfColorPicker
9 | {
10 | ///
11 | /// Describes a color in terms of Hue, Saturation, and Value (brightness)
12 | ///
13 | public struct HsvColor
14 | {
15 | public double H { get; set; }
16 | public double S { get; set; }
17 | public double V { get; set; }
18 |
19 | public HsvColor(double h, double s, double v)
20 | {
21 | H = h;
22 | S = s;
23 | V = v;
24 | }
25 |
26 | public override bool Equals(object obj) =>
27 | !(obj is HsvColor hsv)
28 | ? false
29 | : hsv.H == H &&
30 | hsv.S == S &&
31 | hsv.V == V;
32 |
33 | public override int GetHashCode()
34 | {
35 | unchecked
36 | {
37 | int hash = 23459;
38 |
39 | hash = (hash * 345679) ^ H.GetHashCode();
40 | hash = (hash * 345679) ^ S.GetHashCode();
41 | hash = (hash * 345679) ^ V.GetHashCode();
42 |
43 | return hash;
44 | }
45 | }
46 |
47 | public static bool operator ==(HsvColor left, HsvColor right) => left.Equals(right);
48 |
49 | public static bool operator !=(HsvColor left, HsvColor right) => !(left == right);
50 | }
51 | }
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/abbaye/WpfColorPicker/51a2025f07967706b4f420ffa3c6068ca83b57b8/Sources/WpfColorPicker/Properties/AssemblyInfo.cs
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/Themes/generic.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
16 |
17 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
71 |
72 |
130 |
131 |
132 |
181 |
182 |
238 |
239 |
240 |
241 |
337 |
338 |
339 |
340 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
838 |
839 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/WpfColorPicker.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.0;net45;net47
5 | true
6 | WpfColorPicker
7 | WpfColorPicker
8 | WpfColorPicker user control
9 | true
10 | Derek Tremblay (derektremblay666@gmail.com)
11 | Derek Tremblay (derektremblay666@gmail.com)
12 |
13 | .NET FRAMEWORK 4.5/4.7 AND .NET CORE 3.0
14 | Wpf ColorPicker is a set of customs usercontrol that can take color in your app.
15 |
16 |
17 | WpfColorPicker
18 | MIT
19 | 0.1.2
20 | 0.1.2
21 | 0.1.2
22 | true
23 |
24 | wpf-colorpicker;colorpicker;color;picker;wpf-controls
25 |
26 |
27 | preview
28 | https://github.com/abbaye/WpfColorPicker
29 | false
30 |
31 | license.txt
32 |
33 |
34 |
35 | TRACE;DEBUG
36 | x64
37 |
38 |
39 |
40 |
41 | True
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Sources/WpfColorPicker/license.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Adam Anderson, Derek Tremblay
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.
--------------------------------------------------------------------------------