Introduction
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
XAML Code
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Colors (Click to save to the Clipboard)" Height="300" Width="300">
<Grid>
<ScrollViewer Name="Scroll_Viewer">
<UniformGrid Name="Uni_form_Grid">
-->
</UniformGrid>
</ScrollViewer>
</Grid>
</Window>
C# Code
public Window1()
{
InitializeComponent();
Uni_form_Grid.Children.Clear();
Type t = typeof(System.Windows.Media.Brushes);
PropertyInfo[] colors = t.GetProperties();
int i = -1;
foreach (PropertyInfo color in colors)
{
i++;
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.ToolTip = hex;
rectangle.Stroke = Brushes.Black;
rectangle.MouseDown += new MouseButtonEventHandler(rectangle_MouseDown);
Uni_form_Grid.Children.Add(rectangle);
}
}
void rectangle_MouseDown(object sender, MouseButtonEventArgs e)
{
Rectangle rect = (Rectangle)sender;
Clipboard.SetData("Text", rect.ToolTip.ToString());
}
History
- 2nd July, 2008: Initial post