Monday, March 9, 2009

Silverlight Contrib [1] - ColorPicker

In this part of my small series about Silverlight Contrib I will introduce very useful control - ColorPicker. ColorPicker allows you to select color by the very user friendly way. It was one of the things I miss.

Before start playing with ColorPicker, read a tutorial, how to get Silverlight Contrib to my project in Visual Studio (in case you do not know that).

Go on
First thing you must to do is put the ColorPicker control in XAML to the page. Don't forget set a SelectedColor, because there is a small bug. If you don't select a color in definition, your ColorPicker won't work till you move with vertical axis.



Now you have a wonderful ColorPicker in your page.



Now, we add a rectangle and TextBlock, which we use to demonstrate event SelectedColorChanging.



It could seems like this:



The only thing we have to do, when we want to change color of rectangle and text, is say: when the color in ColorPicker is changing, the Foreground in TextBlock and Fill in Rectangle will change too. For it we use an event SelectedColorChanging.



Now we should play with it.

Playing with color's components
This thing is different against Alfa versions. Now you have a direct access to RGB components. You can call it by SelectedColor.A/R/G/B.

Small example of using:

XAML



C#



Result:



Online demo
Online demo you can find here.

Source code
Code you can download here.

0 comments:

Post a Comment