WPF Color Picker
Here, I am going to demonstrate how to use WPF Extended Toolkit color picker and how to store colors in the database.
Step 1- Add Reference to your program
To enable color picker to your program, you need to install WPF Extended Toolkit from NuGet Package Manager.
Right click on your Project >> select Manage NuGet Packages >> search for Extended WpfTool kit.
Step 2
Include xmlns:xctk="http://schemas/xceed.com/wpf/xaml/toolkit" reference in your XAML file.
Step 3 - Create Color Picker.
- <xctk:ColorPicker Name="cp" Grid.Column="1" Margin="161,377,563,33" DisplayColorAndName="True" SelectedColorChanged="cp_SelectedColorChanged_1" AvailableColorsSortingMode="HueSaturationBrightness" ></xctk:ColorPicker>

Step 4 - Convert hex value to long
- private void cp_SelectedColorChanged_1(object sender, RoutedPropertyChangedEventArgs<Color?> e)
- {
- if (cp.SelectedColor.HasValue)
- {
- Color C = cp.SelectedColor.Value;
- Red = C.R;
- Green = C.G;
- Blue = C.B;
- long colorVal = Convert.ToInt64(Blue * (Math.Pow(256, 0)) + Green * (Math.Pow(256, 1)) + Red * (Math.Pow(256, 2)));
- }
- }
Store this colorVal to the database.
Step 5 - Retrive from Database
- byte[] bytes = BitConverter.GetBytes(ItmMasModelList[i - 2].ColorKy);//ItmMasModelList[i - 2].ColorKy coming from database
- leftBtn.Background = new SolidColorBrush(Color.FromRgb(bytes[2], bytes[1], bytes[0]));
- leftBtn.Style = ItemNewButtonStyle;

vipul vaishnavPosted Dec 25, 2021, 10:32 AM
Hello congratulations ciruthika can you share a source code of this project WPF Color Picker In C#[email protected]
Viknaraj ManogararajahPosted Aug 17, 2018, 8:46 AM
congratulations.....
Rafnas T PPosted Aug 16, 2018, 2:24 AM
Nice share and expecting more shares.
Avnish KumarPosted Aug 13, 2018, 12:29 AM
Nice explanation.