Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ColorPicker In Windows Phone 8

0.00/5 (No votes)
12 Nov 2014 2  
This code sample demonstrates how to set color to any control using colorpicker. For this, you have to create a new Windows phone app.

Introduction

This code sample demonstrates how to set color to any control using colorpicker. For this, you have to create a new Windows phone app.

Step 1: Create a New Windows Phone App

Step 2: Add Toolkit

For colorpicker control, you have to install toolkit or add reference to that DLL file. For that, right click on reference and choose add reference option in which choose browse option and browse their DLL file (Coding4Fun.Phone.Controls.dll).

After adding this DLL file, it will appear in the reference file.

Step 3: Set MainPage UI as Per Below

Add namespace MainPage.xaml page:

  xmlns:c4fToolkit="clr-namespace:Coding4Fun.Phone.Controls;assembly=Coding4Fun.Phone.Controls"

Write this code in MainPage.xaml:

  <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <StackPanel>
            <c4fToolkit:ColorPicker x:Name="picker" Height="300" 
                 Width="400" ColorChanged="picker_ColorChanged" />
             <Rectangle  Height="150" Margin="0,30,0,0" Width="150" x:Name="ColorRect"/>
            </StackPanel>
   </Grid>

Step 4: Add colorpicker Change Event and Write this Code in MainPage.xaml.cs Page

Add namespace using System.Windows.Media;; for SolidColorBrush.

It will set rectangle color.

   private void picker_ColorChanged(object sender, System.Windows.Media.Color color)
    {
            ColorRect.Fill = new SolidColorBrush(color);
    }

Step 5: Output of this Code

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here