Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get phone accent brush programmatically c#

I have textbox in xaml

<TextBlock Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="{StaticResource PhoneFontSizeLarge}" FontFamily="{StaticResource PhoneFontFamilySemiLight}" Margin="12,10,12,0" />

How can I get value of phoneaccentbrush, programmatically (c#) from system resource of windows phone 7 / 7.5 / 8 so that i can set the foreground-color to match the accent selected in the WP's settings.

like image 870
Isaiyavan Babu Karan Avatar asked Dec 26 '12 11:12

Isaiyavan Babu Karan


2 Answers

First, you need to create currentAccentColorHex before Constructor of you C# class:

public partial class MainPage : PhoneApplicationPage
{
    Color currentAccentColorHex = (Color)Application.Current.Resources["PhoneAccentColor"];

    // Constructor
    public MainPage()
    {          
        //...

and then use it wherever you need to set color for the control: Example for Background property for control MyControl:

SolidColorBrush backColor = new SolidColorBrush(currentAccentColorHex);
MyControl.Background = backColor;

Hope this help

like image 182
Spaso Lazarevic Avatar answered Nov 06 '22 13:11

Spaso Lazarevic


thanks Spaso :) I did little more research and with your help I came up with following code

var phoneAccentBrush =  new SolidColorBrush((App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color);
like image 34
Isaiyavan Babu Karan Avatar answered Nov 06 '22 14:11

Isaiyavan Babu Karan