Using ColorbOx from Code

Mar 12 at 7:39 AM
Thanks for this product. I have a question though.

How can I set the binding from code behind?

Example xaml code:
<Border x:Name="bdrTest" Background="{Binding ElementName=CB, Path=Brush}" />

What is the equivalent C# code for the binding?
Mar 15 at 4:48 AM
I have solved this problem.
Set up a wpf window as per the docs. I have called my colorpicker "cPick"

Now suppose you have a canvas object called "canDraw" and you create a rectangle in code to be shown on it like this:
                //create a rectangle
                Rectangle aRect;
                aRect = new Rectangle();
                aRect.Stroke = new SolidColorBrush(Colors.Black);
                aRect.StrokeThickness = 1;
                aRect.Fill = new SolidColorBrush(Colors.Black);
                aRect.Width = 200;
                aRect.Height = 200;
                Canvas.SetLeft(aRect, 0);
                Canvas.SetTop(aRect, 0);
We want to bind this to the color Picker "cPick" using the Brush property of "cPick"
                //bind to colorbox
                Binding b = new Binding();
                b.Source = cPick;
                b.Path = new PropertyPath("Brush");
                //b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
                aRect.SetBinding(Shape.FillProperty, b);
Now when you run your program, you will be able to set the color Properties using ColorBox