We often use a color selection box for winform programs, but this class is not provided in WP7 for our call. Today we see an open-source project coding4fun, the following describes how to use the hexagonal color selection box: first download to the DLL package we want to use. The address will be provided later in the blog. Create a project in vs2010, add reference, and add namespace declaration in the mainpage. XAML file header. Then add the following code directly to the place where the hexagonal color selection box needs to be added:
<c4fControls:ColorHexagonPicker />
The effect is as follows:Coding4fun provides the following attributes for this hexagonal color extraction device:
This is a color independent attribute, which determines the color selection result in the face color selector. Type: Color
Color brightness step, type: int
Color darkness step, type: int
Color: select the size of the rectangle, type: double
The step of the gray value, type int
The following is an example of the selected color painter. You can check the effect by referring to the Code:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <c4fControls:ColorHexagonPicker ColorSize="10" ColorBrightnessSteps="3" Margin="-147,22,147,75" Height="510" Width="456" /> <c4fControls:ColorHexagonPicker ColorSize="10" ColorBrightnessSteps="5" Margin="9,22,-9,75" Height="510" Width="456" /> <c4fControls:ColorHexagonPicker ColorSize="10" ColorDarknessSteps="3" Margin="-125,210,125,-113" Height="510" Width="456" /> <c4fControls:ColorHexagonPicker ColorSize="10" ColorDarknessSteps="5" Margin="53,210,-53,-113" Height="510" Width="456" /> <c4fControls:ColorHexagonPicker ColorSize="10" GreyScaleSteps="3" Margin="-125,416,125,-319" Height="510" Width="456" /> <c4fControls:ColorHexagonPicker ColorSize="10" GreyScaleSteps="5" Margin="76,441,-76,-344" Height="510" Width="456" /></Grid>
To set a region without hexagonal colors, see the following code:
<c4fControls:ColorHexagonPicker ColorSize="20" ColorDarknessSteps="0" ColorBrightnessSteps="0" Margin="94,260,-94,-163" Height="510" Width="456" />
Next is an example of color paint brush binding. Front-end binding:
<Grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0"> <c4fcontrols: colorhexagonpicker colorsize = "20" name = "colorpicker" margin = "-6, 6, 91 "Height =" 510 "width =" 456 "/> <rectangle Height =" 80 "horizontalalignment =" Left "fill =" {binding elementname = colorpicker, path = solidcolorbrush} "margin =" 143,366, 146 "name =" rectangle1 "stroke =" black "strokethickness =" 1 "verticalignment =" TOP "width =" "/> <textblock fontsize =" 30 "Height =" 40 "horizontalalignment =" Left "margin =" 12,366, 125 "name =" textblock1 "text =" color binding: "verticalalignment =" TOP "width =" "/> </GRID>
Use the colorchanged event to bind the background:
<Grid X: Name = "contentpanel" grid. row = "1" margin = "12, 0, 12, 0"> <c4fcontrols: colorhexagonpicker colorsize = "20" name = "colorpicker" colorchanged = "colorpicker_colorchanged" margin = "-6, 6, 91 "Height =" 510 "width =" 456 "/> <rectangle Height =" 80 "horizontalalignment =" Left "margin =" 143,366, 146 "name =" rectangle1 "stroke =" black "strokethickness =" 1 "verticalignment =" TOP "width =" "/> <textblock fontsize =" 30 "Height =" 40 "horizontalalignment =" Left "margin =" 12,366, 125 "name =" textblock1 "text =" color binding: "verticalalignment =" TOP "width =" "/> </GRID>
private void ColorPicker_ColorChanged(object sender, Color color) { this.rectangle1.Fill = new SolidColorBrush(color); }Source Project address: coding4fun