|
This will be small article on how to get accentcolor in Windows Phone 7. In my previous article Part 15 - Windows Phone 7 Detect Theme we discussed about how to detect theme. In Windows Phone 7 theme is combination of background and accent color. The background color can be dark and light and there are 10 standard accent colors to choose from to apply in the application.
Below is the list of colors available in Windows Phone 7 along with Hex and RGB values.
| Accent Color |
Hex |
RGB |
| magenta |
#FFD80073 |
216, 0, 115 |
| purple |
#FFA200FF |
162, 0, 255 |
| teal |
#FF00ABA9 |
0, 176, 169 |
| lime |
#FFA2C139 |
162, 193, 57 |
| brown |
#FFA05000 |
160, 80, 0 |
| pink |
#FFE671B8 |
230, 113, 184 |
| mango |
#FFF09609 |
240, 150, 9 |
| blue |
#FF1BA1E2 |
27, 161, 226 |
| red |
#FFE51400 |
229, 20,0 |
| green |
#FF339933 |
51, 153, 51 |
Let's write code:
Step 1: Create a new Windows Phone Application project. Select Silverlight for Windows Phone installed templates.
Step 2: Replace TitlePanel StackPanel of MainPage.xaml with
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:Name="ApplicationTitle" Text="Demo" Style="{StaticResource PhoneTextNormalStyle}"/> <TextBlock x:Name="PageTitle" Text="Accent Color" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel>
Step 3: Add two textblocks in the ContentPanel grid of MainPage.xaml. If you notice the style of TextBlock is set to PhoneTextAccentStyle which will set the color of textbox according to the accent color of the Windows Phone 7.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <TextBlock Height="35" HorizontalAlignment="Left" Margin="21,205,0,0" Name="textHexAccentColor" Width="400" Style="{StaticResource PhoneTextAccentStyle}"/> <TextBlock Height="35" HorizontalAlignment="Left" Margin="21,305,0,0" Name="textRGBAccentColor" Width="400" Style="{StaticResource PhoneTextAccentStyle}"/> </Grid>
Step 4: Open MainPage.xaml.cs and place below code in the constructor of MainPage.
public MainPage() { InitializeComponent(); Color currentAccentColorHex = (Color)Application.Current.Resources["PhoneAccentColor"]; textHexAccentColor.Text = "Accent color in Hex is: " + currentAccentColorHex.ToString(); textRGBAccentColor.Text = "Accent color in RGB is: " + currentAccentColorHex.R.ToString() + "," + currentAccentColorHex.G.ToString() + "," + currentAccentColorHex.B.ToString() ; }
Now run the application, the color of text will be selected theme.

In the above shown image the text color is mango because i have selected accent color as mango from setting.
This ends the article of working with accent color in Windows Phone 7.
|