Custom Color Picker for Windows Phone

Working with Windows Phone applications sometimes you need to use some sort of the Color picker. But not Color picker that have ability to choose from millions of different colors but Color picker with just tens of the custom colors. I implemented this Color Picker in my Windows Phone app ColoringBook. So, to be clear, I want to chose colors from pages like these:


Color picker page

First of all, we need do define XAML to get small color rectangle in rows and columns. We will use regular ListBox with small addition of ItemPanelTemplate defined as WrapPanel. To use WrapPanel you need to use Windows Phone Toolkit or RadControls. We will use controls with WP toolkit. In next examples I’ll use code for Windows Phone 8 but almost the same code would be for Windows Phone 7.

XAML code for color picker page are:

    <!--LayoutRoot is the root grid where all page content is placed-->

        <!--ContentPanel - place additional content here-->

To use toolkit you need to install it first because it is not part of the SDK for Windows Phone 8. The best way to install it is to use NuGet (tool that help you to install packages into your Visual Studio project) from Visual Studio:

Tools / Library Package Manager / Package Manager Console

and the use next command: Install-Package WPtoolkit


If you don’t have NuGet I strongly suggest you to install it in you Visual Studio environment (Tools / Extensions and Updates / NuGet Package Manager).

When you install WP toolkit, you need to include it in the XAML. I also add TiltEffect into page to see what color are picked (you’ll see some small animation when you touch one of the rectangle filled with color).  And finally, in order to get color in rectangle, we used ColorToBrushConverter in order to be able to fill rectangle with selected Color. Fill control need SolidColorBrush type of object and we use converter to convert from Color type to SolidColorBrush type.

The size of the rectangle can change using Width and Height property of the rectangle. For small size we use 65 px and for large size we use 100 px. You can use size depending how much colors do you want on your color picker page.

When we have definition of our color picker page, we need to fill these rectangle with colors. So, the next step is code behind explanation of our ColorPickerPage.

Code behind for color picker page are:

First we define colorNames and uintColors for definition of our custom colors:

static string[] colorNames =

static uint[] uintColors =

You can find list of colors in alphabetical order on Wiki page List of colors: A-M and List of colors: N-Z. For uintColors variable use Hex(RGB) value from Wiki page but add FF value after 0x so the format for uinColors is for example for yellow color: 0xFFFFFF00.

When ColorPickerPages is loaded we need to use all the colors from our static variable and use it as ItemSource for ListBox control:

private void ColorPickerPage_Loaded(object sender, RoutedEventArgs e)
  List item = new List();
  for (int i = 0; i < 66; i++)   {     item.Add(new ColorItem() { Text = colorNames[i], Color = ConvertColor(uintColors[i]) });   };   listBox.ItemsSource = item; //Fill ItemSource with all colors } private Color ConvertColor(uint uintCol) {   byte A = (byte)((uintCol & 0xFF000000) >> 24);
  byte R = (byte)((uintCol & 0x00FF0000) >> 16);
  byte G = (byte)((uintCol & 0x0000FF00) >> 8);
  byte B = (byte)((uintCol & 0x000000FF) >> 0);

  return Color.FromArgb(A, R, G, B); ;

As our definition of our colors is in Hexadecimal format we use ConvertColor function to split hex value into A,R,G,B component and use Color.FromArgb to get Color type that we could use in our app.

To store color item (text and color value)  we use ColorItem class with two propeties:

public class ColorItem
  public string Text { get; set; }
  public Color Color { get; set; }

And finally, when one of the color is selected SelectionChanged is triggered:

private void lstColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
  if (e.AddedItems.Count > 0)
    (Application.Current as App).CurrentColorItem = ((ColorItem)e.AddedItems[0]);

We use global CurrentColorItem property to store selected ColorItem. CurrentColorItem  is define in App.xaml.cs class as:

public ColorItem CurrentColorItem { set; get; }

How to call ColorPickerPage

When we have ColorPickerPage defined, we need to call it and receive color and name of the color. For that purpose we use MainPage.xaml. Let say, just for presentation purpose, that we want to fill rectangle of the firs page of our app with some custom colors and the name of the same color in text box. The main purpose of main page is to show selected color and name of the color.


Also, we use IsolatedStorageSettings to store last used ColorItem. When app is start for the first time, we choose some color to be default (Cyan) and when we are navigating to the main page and if we have value for the global variable CurrentColorItem then means that we select some color from ColorPickerPage.


public partial class MainPage : PhoneApplicationPage
  private ColorItem _colorItem;
  IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

  // Constructor
  public MainPage()

  private void InitializeSettings()
    if (!settings.Contains("LastColorItem"))
      ColorItem item = new ColorItem();
      item.Color = Colors.Cyan;
      item.Text = "Cyan";
      settings.Add("LastColorItem", item);

  protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
    settings["LastColorItem"] = _colorItem;

  protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)

    //get settings value
    if (settings.Contains("LastColorItem"))
      _colorItem = (ColorItem)settings["LastColorItem"];

    ColorItem myColorItem = (Application.Current as App).CurrentColorItem;
    if (myColorItem != null)
      _colorItem = (ColorItem)myColorItem;

    this.ColorName.Text = _colorItem.Text;
    this.FillRect.Fill = new SolidColorBrush(_colorItem.Color);

  private void PickColorButton_Click(object sender, RoutedEventArgs e)
    NavigationService.Navigate(new Uri("/ColorPickerPage.xaml", UriKind.Relative));

In OnNavigatedTo method we use local variable _colorItem which i s ColorItem type to fill rectangle with color and Text box with text whether from last used color (LastColorItem stored in IsolatedStorageSettings) or from ColorPickerPage (using CurrentColorItem). When we are navigating from MainPage we store last used color in IsolatedStorageSettings.

In MainPage we use three controls in StackPanel, Rectangle for color, TextBox for name of the color, Button for calling ColorPickerPage:

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">    
	<StackPanel Orientation="Vertical">        
		<Rectangle x:Name="FillRect" Width="400" Height="200" Stroke="White" Margin="0,50,0,20"/>        
		<TextBox x:Name="ColorName" HorizontalContentAlignment="Center" Width="400"/>        
		<Button Height="80" Width="200" Content="Pick Color" Click="PickColorButton_Click"/>    

That is it!

I hope that you can find this post useful.

You can find source code for this sample in Nokia Wiki article on

About Spaso Lazarevic

Spaso Lazarevic is Software Engineer working with Microsoft technologies. Microsoft MVP for Visual C# 2012 - 2016.
This entry was posted in Programming, Windows Phone and tagged , . Bookmark the permalink.

3 Responses to Custom Color Picker for Windows Phone

  1. Mike says:

    Where is the ‘Converters’ in xmlns:converters=”clr-namespace:CustomColorsPicker.Converters”
    I’m getting the following error: The type ‘converters:ColorToBrushConverter’ was not found.

  2. Vincent says:

    Can’t get it to work on WP8.1, do you have a new tutorial how to do it on the RT build?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s