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