Oleg's profileOleg V. Polikarpotchkin ...BlogNetwork Tools Help

Blog


    June 09

    RainbowBox Element

    This element is the one more control from the ColorPicker constituent controls bug in addition to the published in my recent posts.

    RainbowBox element is designed as the tool to select a Color from the color spectrum and is close to the one in the Windows Common Color dialog. It extends the FrameworkElement.

    The horizontal color spectrum is overlaid by the vertical gradient ranging from transparent color to Gray color. That is the sample.

    RainbowBox

    You select the color with the color selector (small white circle with black border). You can drag it with the mouse or just click anywhere on the RainbowBox element surface. You can provide you own color selector drawing with the RainbowBox.Selector Dependency Property.

    Read-only SelectedColor Dependency Property of the RainbowBox used to get the value of the Color selected. User can change the SelectedColor property from its code using the SelectorPosition property. The SelectorPosition property gets or sets the selector position normalized to [0,1 0,1] rectangle. Another way to change the SelectedColor property from the code is the RainbowBox.TrySetSelectedColor method. It gets the color argument and tries to find that color in the Rainbow. On success it sets the selector position accordingly and returns true; otherwise it returns false. When the SelectedColor changes the RainbowBox raises the SelectedColorChanged event.

    The Rainbow Dependency Property allows to get or set the color spectrum. It's of the GradientStopCollection type i.e. represents the sequence of colors along with the position of the color in the spectrum. By default the spectrum is the sequence of equally spaced Red, Orange, Yellow, Green, Blue, Indigo, Violet, Red colors. When the Rainbow property changes the RainbowBox tries to find the current SelectedColor value in the new Rainbow. On success it sets the selector position accordingly; otherwise it sets the selector position to the top-left corner and changes its SelectedColor to the value corresponding to that position.

    The code

    You can download the code and the samples here:


    The archive contains my WPFGears library with samples, tests, etc. It’s the Visual Studio 2008 SP1 solution targeted to .NET Framework 3.5.

    You’ll find RainbowBoxSample project there. RainbowBox element code is in the WPFGears library project ColorPickerControls folder.

    Regards,
    Oleg V. Polikarpotchkin

    Technorati Теги: ,,,

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://ov-p.spaces.live.com/blog/cns!39D56F0C7A08D703!296.trak
    Weblogs that reference this entry
    • None