eomer
eomer

Reputation: 3624

windows phone 8 xaml set the color of a button on click

I am working on win8 phone project whenever I click a button the buttons background changes to phones accent color or on a textBox the border color changes to phones accent color or the color of the keyboard buttons changes to phones accent color ... I tried to overwrite the PhoneAccentBrush in application.resources < solidColorBrush x:Key="PhoneAccentBrush" color="white" /> but it didnt work is there any way to change Phone Accent Color for all elements in my app ??

Upvotes: 1

Views: 7740

Answers (3)

Gianluca P.
Gianluca P.

Reputation: 1551

Without copying whole style with blend you can simply override default theme:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default">
                <!-- Button pressed color -->
                <SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="OrangeRed"/>
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Application.Resources>

tested with wp8.1 at least, anyway I found out ButtonPressedBackgroundThemeBrush with blend ;)

Upvotes: 3

Khushbu
Khushbu

Reputation: 1

    private void btnSignIn_Click(object sender, RoutedEventArgs e)
    {
        btnSignIn.Background = GetColorFromHexa("#59BD56");
    }
    public SolidColorBrush GetColorFromHexa(string hexaColor)
    {
        byte R = Convert.ToByte(hexaColor.Substring(1, 2), 16);
        byte G = Convert.ToByte(hexaColor.Substring(3, 2), 16);
        byte B = Convert.ToByte(hexaColor.Substring(5, 2), 16);
        SolidColorBrush scb = new SolidColorBrush(Color.FromArgb(0xFF, R, G, B));
        return scb;
    }

Upvotes: 0

Paul Annetts
Paul Annetts

Reputation: 9604

You can change the default style of all Button controls in your app such that it doesn't use {StaticResource PhoneAccentBrush} in the Pressed state.

Open Blend and create a simple WP8 project, put a Button in it and then grab a copy of the template (right click on the button and Edit a copy). See Jeff Wilcox's blog for a step-by-step description of the process.

Then you can paste the template into your App.xaml. If you remove the x:Keyit becomes the default style for that control.

Alternately you could check this StackOverflow question about overriding the theme everywhere.

Upvotes: 5

Related Questions