Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set StackPanel background to WP7 selected accent (theme) color

I am wondering if it is possible to set the background of my StackPanel to the Windows Phone 7 user selected accent (theme) color. I have heard that you are supposed to use styles so it can be used for all the StackPanels on the current xaml page. However I am a bit lost.

Example of my current static background color:

<StackPanel Width="400" Background="#FF1BA1E2" Margin="0, 10, 0, 0" Tag="ABC">
       <TextBlock Text="ABC" FontSize="50" Margin="10" />
</StackPanel>

Thanks for the help in advance.

PS: Just in case anyone is wondering the hexadecimal value "#FF1BA1E2" is the color of the default WP7 blue accent (theme).

like image 964
Marko Avatar asked Mar 22 '11 00:03

Marko


2 Answers

Use the built in static resources to automatically get the theme color:

Background="{StaticResource PhoneAccentBrush}"
like image 79
Matt Lacey Avatar answered Oct 31 '22 16:10

Matt Lacey


i have encountered the same exception while trying this. just try Apply Binding to the Background through Properties tab. or hardcode this into the xaml file, to the stackpanel element

Background="{Binding Source={StaticResource PhoneAccentBrush}}"

it solves the exception. :)

like image 40
VichitraVij Avatar answered Oct 31 '22 15:10

VichitraVij