Reputation: 161
In my application the user can choose what colour they would like a particular feature of the app to be.
They can choose from a variety of colours which works fine, however when trying to set the Grid's background to the accent colours; when chosen, a NullReferenceException was unhandled
error appears.
The code I am using is:
Color accentColour = (Color)Application.Current.Resources["PhoneAccentColor"];
gridColour.Background = new SolidColorBrush(accentColour);
Anyone know what I am doing wrong? (I've also tried using a Rectangle and it's .Fill
property).
Thanks.
[SOLVED: Post solved in comments.]
Upvotes: 0
Views: 88
Reputation: 2621
You can try that code in OnNavigatedTo
Event. Its Working.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Color accentColour = (Color)Application.Current.Resources["PhoneAccentColor"];
ContentPanel.Background = new SolidColorBrush(accentColour);
}
Upvotes: 1
Reputation: 9454
I guess you can easily do this by binding the PhoneAccent
color within your XAML
for your Grid.
These threads would be helpful:
Windows Phone 8 Change Accent and Theme Colour
windows phone 8 xaml set the color of a button on click
Hope it helps!
Upvotes: 0