Click here to Skip to main content
13,056,168 members (61,842 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 2 Jul 2008

WPF Colors

, 2 Jul 2008
Rate this:
Please Sign up or sign in to vote.
Show WPF Colors


This is a simple WPF app.
I used ScrollViewer and UniformGrid elements to show colors.
You can save the hexadecimal number of each color to the clipboard by clicking on it.

Using the Code


<Window x:Class="WpfApplication1.Window1"



    Title="WPF Colors (Click to save to the Clipboard)" Height="300" Width="300">
        <ScrollViewer Name="Scroll_Viewer">
            <UniformGrid Name="Uni_form_Grid">
                <!--<span class="code-comment"> Placement of color rectangles  --></span>

C# Code

public Window1()
    Uni_form_Grid.Children.Clear();//Clear all items in Uni_form_Grid
    //collects Brushes' property to an array
    Type t = typeof(System.Windows.Media.Brushes);
    PropertyInfo[] colors = t.GetProperties();
    int i = -1;
    foreach (PropertyInfo color in colors)

        BrushConverter convertor = new BrushConverter();
        Brush brush = convertor.ConvertFromString(color.Name) as Brush;

        string hex = string.Format("#{0}", brush.ToString().Substring(3));

        Rectangle rectangle = new Rectangle();
        rectangle.Fill = brush;//Rectangle background color
        rectangle.ToolTip = hex;//ToolTip of Rectangle
        //rectangle.Height = 20;
        //rectangle.Width = 20;
        rectangle.Stroke = Brushes.Black;//border of Rectangle
        //add event to each Rectangle
        rectangle.MouseDown += new MouseButtonEventHandler(rectangle_MouseDown);


/// <span class="code-SummaryComment"><summary></span>
/// Save data to Clipboard
/// <span class="code-SummaryComment"></summary></span>
void rectangle_MouseDown(object sender, MouseButtonEventArgs e)
    Rectangle rect = (Rectangle)sender;
    Clipboard.SetData("Text", rect.ToolTip.ToString());


  • 2nd July, 2008: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mohammad Dayyan
Iran (Islamic Republic of) Iran (Islamic Republic of)
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralAslam-o-Alaikum Pin
Rai Shahid7-Aug-08 18:32
memberRai Shahid7-Aug-08 18:32 
Do you like to work with me developing projects at your home and submitting it me... if yes then do send me list of tools you have experties....

R@! Shahid

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170728.2 | Last Updated 2 Jul 2008
Article Copyright 2008 by Mohammad Dayyan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid